home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / bn_TD_bignet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  73.0 KB  |  2,644 lines

  1. /*****************************************************************************
  2.   FILE           : bn_TD_bignet.c
  3.   SHORTNAME      : bn_TD_bignet
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : Creates the BIGNET-window for TDNNs. 
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Guenter Mamier
  10.   DATE           : 09.02.93
  11.  
  12.   CHANGED BY     : 
  13.   IDENTIFICATION : @(#)bn_TD_bignet.c    1.11 3/2/94
  14.   SCCS VERSION   : 1.11
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20.  
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <X11/Xlib.h>
  24. #include <X11/Xutil.h>
  25. #include <X11/Xos.h>
  26. #include <X11/cursorfont.h>
  27. #include <X11/Intrinsic.h>
  28. #include <X11/StringDefs.h>
  29. #include <X11/Shell.h>
  30. #include <X11/Xaw/Box.h>
  31. #include <X11/Xaw/Simple.h>
  32. #include <X11/Xaw/Grip.h>
  33. #include <X11/Xaw/Form.h>
  34. #include <X11/Xaw/SmeBSB.h>
  35. #include <X11/Xaw/SmeLine.h>
  36. #include <X11/Xaw/Viewport.h>
  37. #include <X11/Xaw/Label.h>
  38. #include <X11/Xaw/Toggle.h>
  39. #include <X11/Xaw/Command.h>
  40. #include <X11/Xaw/Cardinals.h>
  41. #include <X11/Xaw/AsciiText.h>
  42. #include <X11/Xaw/Scrollbar.h>
  43.  
  44. #include "kr_typ.h"
  45. #include "kernel.h"
  46. #include "ui.h"
  47. #include "glob_typ.h"
  48. #include "kr_ui.h"
  49. #include "ui_mainP.h"
  50. #include "ui_confirmer.h"
  51. #include "ui_textP.h"
  52. #include "ui_utilP.h"
  53. #include "ui_netUpdate.h"
  54. #include "ui_status.h"
  55. #include "ui_xWidgets.h"
  56. #include "ui_fileP.h"
  57. #include "ui_display.h"
  58. #include "ui_event.h"
  59. #include "ui_selection.h"
  60. #include "bn_basics.h"
  61.  
  62. #include "bn_TD_bignet.ph"
  63.  
  64.  
  65.  
  66. /*****************************************************************************
  67.   FUNCTION : bn_createPlanePanel
  68.  
  69.   PURPOSE  : creates the plane panel, which is part of the bignet-window
  70.   NOTES    :
  71.   RETURNS  :
  72.   UPDATE   : 09.02.1993
  73. ******************************************************************************/
  74.  
  75. static void bn_createPlanePannel (Widget parent)
  76.  
  77. {
  78.     Widget pannel;
  79.     Widget plane_edit,current_plane;
  80.     Widget plane_enter,plane_delete,plane_insert,plane_overwrite,
  81.            plane_to_edit,type,pos;
  82.     Widget plane_first,plane_last,plane_prev,plane_next;
  83.     Widget       dummy;
  84.     Arg          arg[25];
  85.     Cardinal     n;
  86.     int colom1 = 25, colom2 = 13, colom3 = 10;
  87.     
  88.     n = 0;  
  89.  
  90.     pannel = XtCreateManagedWidget ("pannel", formWidgetClass, parent, arg, n);
  91.  
  92.     z1s1 = ui_xCreateLabelItem ("Plane                      ", pannel, 
  93.                 colom1 * bn_fontWidth, NULL, NULL); 
  94.     z1s2 = ui_xCreateLabelItem ("Current Plane  ", pannel, 
  95.                 colom2 * bn_fontWidth, z1s1, NULL); 
  96.     z1s3 = ui_xCreateLabelItem ("Edit Plane  ", pannel, 
  97.                 colom3 * bn_fontWidth, z1s2, NULL); 
  98.  
  99.     z2s1   = ui_xCreateLabelItem ("                     Plane:", pannel, 
  100.                   colom1 * bn_fontWidth, NULL, z1s1); 
  101.     dummy = ui_xCreateLabelItem (" ", pannel, 3 * bn_fontWidth, z2s1, z1s1); 
  102.     z2s2   = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z1s1);
  103.  
  104.     z3s1  = ui_xCreateLabelItem ("                      Type: ",pannel,
  105.                  colom1 * bn_fontWidth,NULL,z2s1); 
  106.     dummy = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z3s1,z2s1); 
  107.     z3s2  = ui_xCreateFrameLabelItem ("",pannel,td_bn_intWidth,dummy,z2s1);
  108.     dummy = ui_xCreateLabelItem (" ",pannel,5 * bn_fontWidth,z3s2,z2s1);
  109.     z3s3  = ui_xCreateFrameLabelItem (td_plane_type[TD_PLANE_type],pannel,
  110.                       td_bn_intWidth,dummy,z2s1);
  111.  
  112.     z4s1  = ui_xCreateLabelItem ("      No. of feature units:",pannel,
  113.                  colom1 * bn_fontWidth,NULL,z3s1); 
  114.     dummy = ui_xCreateLabelItem (" ", pannel, 3 * bn_fontWidth,z4s1,z3s1); 
  115.     z4s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z3s1);
  116.     dummy = ui_xCreateLabelItem (" ", pannel, 5 * bn_fontWidth,z4s2,z3s1); 
  117.     z4s3  = ui_xCreateDialogItem ("z4s3", pannel,"",td_bn_intWidth,dummy,z3s1);
  118.  
  119.     z5s1  = ui_xCreateLabelItem ("        Total delay length: ",pannel,
  120.                  colom1 * bn_fontWidth,NULL,z4s1); 
  121.     dummy = ui_xCreateLabelItem (" ", pannel, 3 * bn_fontWidth,z5s1,z4s1); 
  122.     z5s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z4s1);
  123.     dummy = ui_xCreateLabelItem (" ", pannel, 5 * bn_fontWidth,z5s2,z4s1); 
  124.     z5s3  = ui_xCreateDialogItem ("z4s3",pannel, "",td_bn_intWidth,dummy,z4s1);
  125.  
  126.  
  127.     z6s1  = ui_xCreateLabelItem ("z-coordinates of the plane: ",pannel,
  128.                  colom1 * bn_fontWidth,NULL,z5s1); 
  129.     dummy = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z6s1,z5s1); 
  130.     z6s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z5s1);
  131.     dummy = ui_xCreateLabelItem (" ",pannel,5 * bn_fontWidth,z6s2,z5s1); 
  132.     z6s3  = ui_xCreateDialogItem ("z4s3",pannel,"",td_bn_intWidth,dummy,z5s1);
  133.  
  134.     z7s1  = ui_xCreateLabelItem ("             Rel. Position: ",pannel,
  135.                  colom1 * bn_fontWidth,NULL,z6s1); 
  136.     dummy = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z7s1,z6s1); 
  137.     z7s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z6s1);
  138.     dummy = ui_xCreateLabelItem (" ",pannel,5 * bn_fontWidth,z7s2,z6s1);
  139.     z7s3  = ui_xCreateFrameLabelItem (td_plane_pos[TD_PLANE_pos],pannel,
  140.                       td_bn_intWidth,dummy,z6s1);
  141.  
  142.     dummy         = ui_xCreateLabelItem (" ",pannel,
  143.                      15 * bn_fontWidth,NULL,z7s1); 
  144.     
  145.     plane_edit = ui_xCreateLabelItem ("Edit Plane: ",pannel,
  146.                       15 * bn_fontWidth,NULL,dummy); 
  147.     plane_enter = bn_basics_xCreateButtonItem("enter",pannel,plane_edit,dummy);
  148.     XtAddCallback(plane_enter,XtNcallback,
  149.           (XtCallbackProc)enter_plane_PROC,NULL);
  150.  
  151.     plane_insert = bn_basics_xCreateButtonItem ("insert",pannel,
  152.                         plane_enter,dummy);
  153.     XtAddCallback(plane_insert,XtNcallback,
  154.           (XtCallbackProc)insert_plane_PROC,NULL);
  155.  
  156.     plane_overwrite = bn_basics_xCreateButtonItem ("overwrite",pannel,
  157.                            plane_insert,dummy);
  158.     XtAddCallback(plane_overwrite,XtNcallback,
  159.           (XtCallbackProc)overwrite_plane_PROC,NULL);
  160.  
  161.     plane_delete = bn_basics_xCreateButtonItem ("delete",pannel,
  162.                         plane_overwrite,dummy);
  163.     XtAddCallback(plane_delete,XtNcallback,
  164.           (XtCallbackProc)delete_plane_PROC,NULL);
  165.  
  166.     dummy = ui_xCreateLabelItem(" ",pannel,15 * bn_fontWidth,NULL,plane_edit); 
  167.     plane_to_edit = bn_basics_xCreateButtonItem ("plane_to_edit",pannel,
  168.                          dummy,plane_edit);
  169.     XtAddCallback(plane_to_edit,XtNcallback,
  170.           (XtCallbackProc)current_plane_to_editor_PROC,NULL);
  171.  
  172.     type = bn_basics_xCreateButtonItem ("type",pannel,plane_to_edit,
  173.                     plane_edit);
  174.     XtAddCallback(type,XtNcallback,(XtCallbackProc)type_PROC,NULL);
  175.  
  176.     pos = bn_basics_xCreateButtonItem ("pos",pannel,type,plane_edit);
  177.     XtAddCallback(pos,XtNcallback,(XtCallbackProc)pos_PROC,NULL);
  178.  
  179.     current_plane = ui_xCreateLabelItem ("Current plane: ",pannel,
  180.                      15 * bn_fontWidth,NULL,dummy); 
  181.     plane_first = bn_basics_xCreateButtonItem ("first",pannel,current_plane,
  182.                            dummy);
  183.     XtAddCallback(plane_first,XtNcallback,
  184.           (XtCallbackProc)beginning_plane_PROC,NULL);
  185.  
  186.     plane_prev = bn_basics_xCreateButtonItem("prev",pannel,plane_first,dummy);
  187.     XtAddCallback(plane_prev,XtNcallback,
  188.           (XtCallbackProc)backward_plane_PROC,NULL);
  189.  
  190.     plane_next = bn_basics_xCreateButtonItem ("next",pannel,plane_prev,dummy);
  191.     XtAddCallback(plane_next,XtNcallback,
  192.           (XtCallbackProc)forward_plane_PROC,NULL);
  193.  
  194.     plane_last = bn_basics_xCreateButtonItem ("last",pannel,plane_next,dummy);
  195.     XtAddCallback(plane_last,XtNcallback,(XtCallbackProc)end_plane_PROC,NULL);
  196. }
  197.  
  198.  
  199.  
  200. /*****************************************************************************
  201.   FUNCTION : bn_createLinkPanel
  202.  
  203.   PURPOSE  : creates the link panel, which is part of the bignet-window
  204.   NOTES    :
  205.   RETURNS  :
  206.  
  207.   UPDATE   : 09.02.1993
  208. ******************************************************************************/
  209.  
  210. static void bn_createLinkPannel (Widget parent)
  211.  
  212. {
  213.     Widget pannel;
  214.     Widget dummy,dummy1,dummy2;
  215.     Widget link_edit,current_link;
  216.     Widget link_enter,link_delete,link_overwrite,link_to_edit;
  217.     Widget link_first,link_last,link_prev,link_next;
  218.     Arg          arg[25];
  219.     Cardinal     n;
  220.   
  221.     n = 0;  
  222.  
  223.     pannel = XtCreateManagedWidget("pannel", formWidgetClass, parent, arg, n);
  224.  
  225.  
  226.  
  227.     dummy1 = ui_xCreateLabelItem (" ",pannel,15 * bn_fontWidth,NULL,NULL); 
  228.     z8s2   = ui_xCreateLabelItem (" Current Link ", pannel,
  229.                   14*bn_fontWidth,dummy1,NULL); 
  230.     z8s3   = ui_xCreateLabelItem ("       Edit Link", pannel,
  231.                   16*bn_fontWidth,z8s2,NULL); 
  232.     dummy2 = ui_xCreateLabelItem (" ",pannel,15 * bn_fontWidth,NULL,dummy1); 
  233.     z9s1   = ui_xCreateLabelItem ("Source", pannel,
  234.                   8*bn_fontWidth,dummy2,dummy1); 
  235.     z9s2   = ui_xCreateLabelItem ("Target", pannel,
  236.                   8*bn_fontWidth,z9s1,dummy1); 
  237.     z9s3   = ui_xCreateLabelItem ("  Source", pannel,
  238.                   8*bn_fontWidth,z9s2,dummy1); 
  239.     z9s4   = ui_xCreateLabelItem (" Target", pannel,
  240.                   8*bn_fontWidth,z9s3,dummy1); 
  241.     z10s1  = ui_xCreateLabelItem ("Plane", pannel,
  242.                   15*bn_fontWidth,NULL,dummy2); 
  243.     z10s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,z10s1,dummy2);
  244.     dummy  = ui_xCreateLabelItem (" ",pannel,1 * bn_fontWidth,z10s2,dummy2); 
  245.     z10s3  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,dummy2);
  246.     dummy  = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z10s3,dummy2); 
  247.     z10s4  = ui_xCreateDialogItem("z10s4", pannel,"",td_bn_intWidth,
  248.                   dummy,dummy2);
  249.     dummy  = ui_xCreateLabelItem(" ",pannel,1 * bn_fontWidth,z10s4,dummy2); 
  250.     z10s5  = ui_xCreateDialogItem("z10s5", pannel,"",td_bn_intWidth,
  251.                   dummy,dummy2);
  252.     z11s1  = ui_xCreateLabelItem(" ", pannel, 15*bn_fontWidth,NULL,z10s1); 
  253.  
  254.     z12s1  = ui_xCreateLabelItem ("     Receptive Field Coordinates", pannel,
  255.                   30*bn_fontWidth,dummy2,z11s1); 
  256.     z13s1  = ui_xCreateLabelItem ("1st feat. unit:", pannel,
  257.                   15*bn_fontWidth,NULL,z12s1); 
  258.     z13s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,z13s1,z12s1);
  259.     dummy  = ui_xCreateLabelItem (" ",pannel,1 * bn_fontWidth,z13s2,z12s1); 
  260.     z13s3  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z12s1);
  261.     dummy  = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z13s3,z12s1); 
  262.     z13s4  = ui_xCreateDialogItem("z13s4", pannel, "",td_bn_intWidth,
  263.                   dummy,z12s1);
  264.     dummy  = ui_xCreateLabelItem (" ",pannel,1 * bn_fontWidth,z13s4,z12s1); 
  265.     z13s5  = ui_xCreateDialogItem("z13s5", pannel, "",td_bn_intWidth,dummy,
  266.                   z12s1);
  267.     z15s1  = ui_xCreateLabelItem ("         width:", pannel,
  268.                   15*bn_fontWidth,NULL,z13s1); 
  269.     z15s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,z15s1,z13s1);
  270.     dummy  = ui_xCreateLabelItem (" ",pannel,1 * bn_fontWidth,z15s2,z13s1); 
  271.     z15s3  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z13s1);
  272.     dummy  = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z15s3,z13s1); 
  273.     z15s4  = ui_xCreateDialogItem("z15s4", pannel, "",td_bn_intWidth,
  274.                   dummy,z13s1);
  275.     dummy  = ui_xCreateLabelItem (" ",pannel,1 * bn_fontWidth,z15s4,z13s1); 
  276.     z15s5  = ui_xCreateDialogItem("z15s5", pannel, "",td_bn_intWidth,
  277.                   dummy,z13s1);
  278.  
  279.     z16s1  = ui_xCreateLabelItem ("  delay length:", pannel,
  280.                   15*bn_fontWidth,NULL,z15s1); 
  281.     z16s2  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,z16s1,z15s1);
  282.     dummy  = ui_xCreateLabelItem (" ",pannel,1 * bn_fontWidth,z16s2,z15s1); 
  283.     z16s3  = ui_xCreateFrameLabelItem ("", pannel,td_bn_intWidth,dummy,z15s1);
  284.     dummy  = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z16s3,z15s1); 
  285.     z16s4  = ui_xCreateDialogItem("z16s4", pannel, "",td_bn_intWidth,
  286.                   dummy,z15s1);
  287.  
  288.     dummy  = ui_xCreateLabelItem (" ",pannel,15 * bn_fontWidth,NULL,z16s1); 
  289.     link_edit = ui_xCreateLabelItem ("Edit Link: ",pannel,
  290.                      15 * bn_fontWidth,NULL,dummy); 
  291.     link_enter = bn_basics_xCreateButtonItem ("enter",pannel,link_edit,dummy);
  292.     XtAddCallback(link_enter,XtNcallback,(XtCallbackProc)enter_link_PROC,NULL);
  293.  
  294.     link_overwrite = bn_basics_xCreateButtonItem ("overwrite",pannel,
  295.                           link_enter,dummy);
  296.     XtAddCallback(link_overwrite,XtNcallback,
  297.           (XtCallbackProc)overwrite_link_PROC,NULL);
  298.  
  299.     link_to_edit = bn_basics_xCreateButtonItem ("link_to_edit",pannel,
  300.                         link_overwrite,dummy);
  301.     XtAddCallback(link_to_edit,XtNcallback,
  302.           (XtCallbackProc)current_link_to_editor_PROC,NULL);
  303.  
  304.     link_delete = bn_basics_xCreateButtonItem ("delete",pannel,
  305.                            link_to_edit,dummy);
  306.     XtAddCallback(link_delete,XtNcallback,
  307.           (XtCallbackProc)delete_link_PROC,NULL);
  308.  
  309.     dummy = ui_xCreateLabelItem (" ",pannel,15 * bn_fontWidth,NULL,link_edit); 
  310.     current_link = ui_xCreateLabelItem ("Current Link: ",pannel,
  311.                     15*bn_fontWidth,NULL,link_edit); 
  312.     link_first = bn_basics_xCreateButtonItem ("first",pannel,
  313.                           current_link,link_edit);
  314.     XtAddCallback(link_first,XtNcallback,
  315.           (XtCallbackProc)beginning_link_PROC,NULL);
  316.  
  317.     link_prev = bn_basics_xCreateButtonItem ("prev",pannel,link_first,link_edit);
  318.     XtAddCallback(link_prev,XtNcallback,
  319.           (XtCallbackProc)backward_link_PROC,NULL);
  320.  
  321.     link_next = bn_basics_xCreateButtonItem ("next",pannel,link_prev,link_edit);
  322.     
  323.     XtAddCallback(link_next,XtNcallback,
  324.           (XtCallbackProc)forward_link_PROC,NULL);
  325.     
  326.     link_last = bn_basics_xCreateButtonItem ("last",pannel,link_next,link_edit);
  327.       XtAddCallback(link_last,XtNcallback,(XtCallbackProc)end_link_PROC,NULL);
  328.  
  329.   }
  330.  
  331.  
  332.  
  333. /*****************************************************************************
  334.   FUNCTION : exit_PROC
  335.  
  336.   PURPOSE  : callback function of the exit-buttom. You are leaving bignet.
  337.   NOTES    :
  338.   RETURNS  :
  339.  
  340.   UPDATE   : 09.02.1993
  341. ******************************************************************************/
  342.  
  343. static void exit_PROC (void)
  344.  
  345. {
  346.     XtDestroyWidget (td_baseWidget);
  347.     td_bignet_widget_open = 0;
  348. }
  349.  
  350.  
  351.  
  352. /*****************************************************************************
  353.   FUNCTION : bn_create_TD_Bignet
  354.  
  355.   PURPOSE  : creates the bignet-window.
  356.   NOTES    :
  357.   RETURNS  :
  358.  
  359.   UPDATE   : 09.02.1993
  360. ******************************************************************************/
  361.  
  362. void bn_create_TD_Bignet (void)
  363.  
  364. {
  365.     Widget       box;
  366.     Widget       create_net,exit,cancel;
  367.     Arg          arg[25];
  368.     Cardinal     n;
  369.     char         buf[40];
  370.  
  371.     if(! td_bignet_widget_open)
  372.       {
  373.        sprintf (buf, "BigNet (Time Delay)");
  374.  
  375.        n = 0;  
  376.        td_baseWidget = XtCreatePopupShell (buf, topLevelShellWidgetClass, 
  377.                     ui_toplevel, arg, n); 
  378.        n = 0;  
  379.        box = XtCreateManagedWidget ("box",boxWidgetClass,td_baseWidget,arg,n);
  380.        bn_createPlanePannel (box); 
  381.        bn_createLinkPannel(box);
  382.  
  383.        create_net = bn_basics_xCreateButtonItem("create_td_net",box,NULL,NULL);
  384.        XtAddCallback(create_net,XtNcallback,
  385.              (XtCallbackProc)create_net_PROC,NULL);
  386.        exit = bn_basics_xCreateButtonItem ("done",box,create_net,NULL);
  387.        XtAddCallback(exit,XtNcallback,(XtCallbackProc)exit_PROC,NULL);
  388.        cancel     = bn_basics_xCreateButtonItem ("cancel",box,exit,NULL);
  389.        XtAddCallback(cancel,XtNcallback,(XtCallbackProc)cancel_net_PROC,NULL);
  390.  
  391.        ui_checkWindowPosition(td_baseWidget);
  392.        XtPopup (td_baseWidget, XtGrabNone);
  393.        ui_xDontResizeWidget(td_baseWidget);
  394.        td_bignet_widget_open = 1;
  395.        if(TD_PLANE_length != 0){
  396.          write_current_plane();
  397.          if(TD_LINK_length != 0) {
  398.            write_current_link();
  399.          }
  400.        }
  401.  
  402.      } else {
  403.     
  404.         ui_confirmOk ("BigNet (Time Delay) already loaded");
  405.  
  406.      }
  407. }
  408.  
  409.  
  410. /*****************************************************************************
  411.   FUNCTION : create_net_PROC
  412.  
  413.   PURPOSE  : creates a SNNS-net in two steps:
  414.              1. calls up a function, which creates SNNS-units
  415.              2. calls up a function, which connections the SNNS-units.
  416.   NOTES    : There are nine different ways 
  417.              (PLANE_TO_PLANE, PLANE_TO_CLUSTER ...) 
  418.              two different planes can be connected.
  419.   RETURNS  :
  420.  
  421.   UPDATE   : 09.02.1993
  422. ******************************************************************************/
  423.  
  424. static void create_net_PROC(void)
  425.  
  426. {
  427.     TD_LINK  *TD_LINK_element=TD_LINK_first_element;
  428.     TD_LINK  *TD_LINK_test=TD_LINK_first_element;
  429.     TD_PLANE *source_plane,*target_plane;
  430.     TD_PLANE *test_plane;
  431.     int move,type_of_connection=1;
  432.     int create=1;
  433.     int j,k;
  434.     int correct = 0;
  435.     int overlap =0;
  436.     char buf1[80],buf2[80];
  437.  
  438.  
  439.     TD_BN_ERROR = 0;
  440.     TD_NET = 1;
  441.  
  442.     strcpy(buf1,"Unused feature units in Plane ");
  443.     strcpy(buf2,"Overlapping Receptive Field in Plane ");
  444.  
  445.  
  446.     /* check whether all feature units are used or any
  447.        receptive fields overlap in the target plane  */
  448.  
  449.  
  450.     TD_LINK_test = TD_LINK_first_element;
  451.  
  452.     for(k=1; k<=TD_PLANE_length; k++){           /* foreach plane        */
  453.     test_plane = get_plane(k);
  454.     for(j=1; j<=(*test_plane).width; j++){   /* foreach feature unit */
  455.         overlap = 0;
  456.         while(TD_LINK_test != NULL){         /* foreach link set     */
  457.         if(TD_LINK_test->SOURCE.plane == k){
  458.             if((j >= (*TD_LINK_test).SOURCE.CLUSTER.x) &&
  459.                (j < ((*TD_LINK_test).SOURCE.CLUSTER.x +
  460.                  (*TD_LINK_test).SOURCE.CLUSTER.width))){
  461.             correct++;
  462.             }
  463.         }else if(TD_LINK_test->TARGET.plane == k){
  464.             if((j >= TD_LINK_test->TARGET.CLUSTER.x) &&
  465.                (j < (TD_LINK_test->TARGET.CLUSTER.x +
  466.                  TD_LINK_test->TARGET.CLUSTER.width))){
  467.             overlap++;
  468.             if(overlap > 1){
  469.                 /* receptive fields overlap */
  470.                 sprintf(buf2,"%s %d",buf2,k);
  471.                 ui_confirmOk(buf2);
  472.                 return;
  473.             }
  474.             }
  475.         }
  476.         TD_LINK_test = TD_LINK_test->next;
  477.         }
  478.         if((correct < 1) && (k != TD_PLANE_length)){ 
  479.         /* not all feature units are used */
  480.         sprintf(buf1,"%s %d",buf1,k);
  481.         ui_confirmOk(buf1);
  482.         return;
  483.         }
  484.         TD_LINK_test = TD_LINK_first_element;
  485.         correct = 0;
  486.     }
  487.     }
  488.  
  489.  
  490.     if(krui_getNoOfUnits() != 0) {
  491.     if(! ui_confirmYes("Create will erase current network. Create?")) {
  492.         create = 0;
  493.     }
  494.     }
  495.  
  496.     if(create && (TD_PLANE_length != 0)) {
  497.  
  498.     krui_deleteNet();
  499.  
  500.     calculate_first_snns_unit_no_of_plane();
  501.     create_snns_unit(); 
  502.  
  503.     while((TD_LINK_element != NULL) && (! TD_BN_ERROR)) {
  504.  
  505.         move               = (*TD_LINK_element).move;
  506.         type_of_connection = (*TD_LINK_element).type_of_connection;
  507.         source_plane       =  get_plane((*TD_LINK_element).SOURCE.plane);
  508.         target_plane       =  get_plane((*TD_LINK_element).TARGET.plane);
  509.    
  510.         switch(type_of_connection) {
  511.           case PLANE_TO_PLANE: {
  512.           make_link(source_plane,0,0,(*source_plane).width,
  513.                 (*source_plane).height,target_plane,0,0,
  514.                 (*target_plane).width,(*target_plane).height);
  515.           break;
  516.           }
  517.           case PLANE_TO_CLUSTER: {
  518.           make_link(source_plane,0,0,(*source_plane).width,
  519.                 (*source_plane).height,target_plane,
  520.                 (*TD_LINK_element).TARGET.CLUSTER.x-1,
  521.                 (*TD_LINK_element).TARGET.CLUSTER.y-1,
  522.                 (*TD_LINK_element).TARGET.CLUSTER.width,
  523.                 (*TD_LINK_element).TARGET.CLUSTER.height);
  524.           break;
  525.           }
  526.           case PLANE_TO_UNIT: {
  527.           make_link(source_plane,0,0,
  528.                 (*source_plane).width,(*source_plane).height,
  529.                 target_plane,(*TD_LINK_element).TARGET.UNIT.x-1,
  530.                 (*TD_LINK_element).TARGET.UNIT.y-1,1,1);
  531.           break;
  532.           }  
  533.           case CLUSTER_TO_PLANE: {
  534.           make_link(source_plane,(*TD_LINK_element).SOURCE.CLUSTER.x-1,
  535.                 (*TD_LINK_element).SOURCE.CLUSTER.y-1,
  536.                 (*TD_LINK_element).SOURCE.CLUSTER.width,
  537.                 (*TD_LINK_element).SOURCE.CLUSTER.height,
  538.                 target_plane,0,0,
  539.                 (*target_plane).width,(*target_plane).height);
  540.           break;
  541.           }
  542.           case CLUSTER_TO_CLUSTER: {
  543.           if(move) {
  544.               make_move_link(source_plane,
  545.                      (*TD_LINK_element).SOURCE.CLUSTER.x-1,
  546.                      (*TD_LINK_element).SOURCE.CLUSTER.y-1,
  547.                      (*TD_LINK_element).SOURCE.CLUSTER.width,
  548.                      (*TD_LINK_element).SOURCE.CLUSTER.height,
  549.                      target_plane,
  550.                      (*TD_LINK_element).TARGET.CLUSTER.x-1,
  551.                      (*TD_LINK_element).TARGET.CLUSTER.y-1,
  552.                      (*TD_LINK_element).TARGET.CLUSTER.width,
  553.                      (*TD_LINK_element).TARGET.CLUSTER.height,
  554.                      (*TD_LINK_element).SOURCE.MOVE.delta_x,
  555.                      (*TD_LINK_element).SOURCE.MOVE.delta_y,
  556.                      (*TD_LINK_element).TARGET.MOVE.delta_x,
  557.                      (*TD_LINK_element).TARGET.MOVE.delta_y);
  558.           }else{
  559.               make_link(source_plane,
  560.                 (*TD_LINK_element).SOURCE.CLUSTER.x-1,
  561.                 (*TD_LINK_element).SOURCE.CLUSTER.y-1,
  562.                 (*TD_LINK_element).SOURCE.CLUSTER.width,
  563.                 (*TD_LINK_element).SOURCE.CLUSTER.height,
  564.                 target_plane,
  565.                 (*TD_LINK_element).TARGET.CLUSTER.x-1,
  566.                 (*TD_LINK_element).TARGET.CLUSTER.y-1,
  567.                 (*TD_LINK_element).TARGET.CLUSTER.width,
  568.                 (*TD_LINK_element).TARGET.CLUSTER.height);
  569.           }
  570.           break;
  571.           }
  572.           case CLUSTER_TO_UNIT: {
  573.           if(move) {
  574.               make_move_link(source_plane,
  575.                      (*TD_LINK_element).SOURCE.CLUSTER.x-1,
  576.                      (*TD_LINK_element).SOURCE.CLUSTER.y-1,
  577.                      (*TD_LINK_element).SOURCE.CLUSTER.width,
  578.                      (*TD_LINK_element).SOURCE.CLUSTER.height,
  579.                      target_plane,
  580.                      (*TD_LINK_element).TARGET.UNIT.x-1,
  581.                      (*TD_LINK_element).TARGET.UNIT.y-1,1,1,
  582.                      (*TD_LINK_element).SOURCE.MOVE.delta_x,
  583.                      (*TD_LINK_element).SOURCE.MOVE.delta_y,
  584.                      (*TD_LINK_element).TARGET.MOVE.delta_x,
  585.                      (*TD_LINK_element).TARGET.MOVE.delta_y);
  586.           }else{
  587.               make_link(source_plane,
  588.                 (*TD_LINK_element).SOURCE.CLUSTER.x-1,
  589.                 (*TD_LINK_element).SOURCE.CLUSTER.y-1,
  590.                 (*TD_LINK_element).SOURCE.CLUSTER.width,
  591.                 (*TD_LINK_element).SOURCE.CLUSTER.height,
  592.                 target_plane,
  593.                 (*TD_LINK_element).TARGET.UNIT.x-1,
  594.                 (*TD_LINK_element).TARGET.UNIT.y-1,1,1);
  595.           }
  596.           break;
  597.           }
  598.           case UNIT_TO_PLANE: {
  599.           make_link(source_plane,(*TD_LINK_element).SOURCE.UNIT.x-1,
  600.                 (*TD_LINK_element).SOURCE.UNIT.y-1,1,1,
  601.                 target_plane,0,0,
  602.                 (*target_plane).width,(*target_plane).height);
  603.           break;
  604.           }
  605.           case UNIT_TO_CLUSTER: {
  606.           if(move) {
  607.               make_move_link(source_plane,
  608.                      (*TD_LINK_element).SOURCE.UNIT.x-1,
  609.                      (*TD_LINK_element).SOURCE.UNIT.y-1,1,1,
  610.                      target_plane,
  611.                      (*TD_LINK_element).TARGET.CLUSTER.x-1,
  612.                      (*TD_LINK_element).TARGET.CLUSTER.y-1,
  613.                      (*TD_LINK_element).TARGET.CLUSTER.width,
  614.                      (*TD_LINK_element).TARGET.CLUSTER.height,
  615.                      (*TD_LINK_element).SOURCE.MOVE.delta_x,
  616.                      (*TD_LINK_element).SOURCE.MOVE.delta_y,
  617.                      (*TD_LINK_element).TARGET.MOVE.delta_x,
  618.                      (*TD_LINK_element).TARGET.MOVE.delta_y);
  619.           }else{
  620.               make_link(source_plane,
  621.                 (*TD_LINK_element).SOURCE.UNIT.x-1,
  622.                 (*TD_LINK_element).SOURCE.UNIT.y-1,1,1,
  623.                 target_plane,
  624.                 (*TD_LINK_element).TARGET.CLUSTER.x-1,
  625.                 (*TD_LINK_element).TARGET.CLUSTER.y-1,
  626.                 (*TD_LINK_element).TARGET.CLUSTER.width,
  627.                 (*TD_LINK_element).TARGET.CLUSTER.height);
  628.           }
  629.           break;
  630.           }
  631.           case UNIT_TO_UNIT: {
  632.           if(move) {
  633.               make_move_link(source_plane,
  634.                      (*TD_LINK_element).SOURCE.UNIT.x-1,
  635.                      (*TD_LINK_element).SOURCE.UNIT.y-1,1,1,
  636.                      target_plane,
  637.                      (*TD_LINK_element).TARGET.UNIT.x-1,
  638.                      (*TD_LINK_element).TARGET.UNIT.y-1,1,1,
  639.                      (*TD_LINK_element).SOURCE.MOVE.delta_x,
  640.                      (*TD_LINK_element).SOURCE.MOVE.delta_y,
  641.                      (*TD_LINK_element).TARGET.MOVE.delta_x,
  642.                      (*TD_LINK_element).TARGET.MOVE.delta_y);
  643.           }else{
  644.               make_link(source_plane,
  645.                 (*TD_LINK_element).SOURCE.UNIT.x-1,
  646.                 (*TD_LINK_element).SOURCE.UNIT.y-1,1,1,
  647.                 target_plane,
  648.                 (*TD_LINK_element).TARGET.UNIT.x-1,
  649.                 (*TD_LINK_element).TARGET.UNIT.y-1,1,1);
  650.           }
  651.           break;
  652.           }
  653.         }            /* switch */
  654.  
  655.         TD_LINK_element = (*TD_LINK_element).next;
  656.  
  657.     }            /* while */    
  658.  
  659.     bn_display_net();
  660. #ifdef DEBUG
  661. /* M.V. */
  662.     j=1;
  663.     while (krui_setCurrentUnit(j) == KRERR_NO_ERROR)
  664.       {
  665.         printf("Unit %d: lln = %d, lun = %d\n",
  666.            j,
  667.            kr_getUnitPtr(j) -> lln,
  668.            kr_getUnitPtr(j) -> lun);
  669.         j++;
  670.       }
  671. #endif
  672.  
  673.     }                /* if */ 
  674.  
  675. }
  676.  
  677.  
  678. /*****************************************************************************
  679.   FUNCTION : calculate_first_snns_unit_no_of_plane
  680.  
  681.   PURPOSE  : calculates the SNNS unit no of the left upper corner of every
  682.              plane.
  683.  
  684.   NOTES    : relative to this unit no, knowing the width and the height of the
  685.              planes, all other SNNS unit numbers of every plane can be 
  686.              calculated. That's important for the function create_snns_unit.
  687.   RETURNS  :
  688.  
  689.   UPDATE   : 09.02.1993
  690. ******************************************************************************/
  691.  
  692. static void calculate_first_snns_unit_no_of_plane(void)
  693.  
  694. {
  695.     TD_PLANE *TD_PLANE_element = TD_PLANE_first_element;
  696.  
  697.     (*TD_PLANE_element).begin = 1;  
  698.     TD_PLANE_element = (*TD_PLANE_element).next;
  699.  
  700.     while(TD_PLANE_element != NULL) {
  701.     (*TD_PLANE_element).begin = (*(*TD_PLANE_element).before).width *
  702.         (*(*TD_PLANE_element).before).height +
  703.         (*(*TD_PLANE_element).before).begin;
  704.     TD_PLANE_element = (*TD_PLANE_element).next; 
  705.     }
  706. }
  707.  
  708.  
  709.  
  710. /*****************************************************************************
  711.   FUNCTION : calculate_x_begin
  712.  
  713.   PURPOSE  : calculates the x-coordinate of a plane, where the plane is
  714.              positioned in the display window.
  715.              plane.
  716.   NOTES    : 
  717.   RETURNS  : The X-Position
  718.  
  719.   UPDATE   : 09.02.1993
  720. ******************************************************************************/
  721.  
  722.  
  723. static int calculate_x_begin(int *new_x_begin,int *old_x_begin,
  724.                  int *x_max,int width,int pos)
  725.  
  726. {
  727.     if(pos == TD_BN_RIGHT) {
  728.    
  729.     *new_x_begin = *x_max + 2; 
  730.     *x_max = *new_x_begin + width;
  731.     *old_x_begin = *new_x_begin;
  732.     return *new_x_begin;
  733.     }else if(pos == TD_BN_BELOW) {
  734.     if(*x_max < (*old_x_begin + width)) {
  735.         *x_max = *old_x_begin + width;
  736.     }
  737.     return *old_x_begin; 
  738.     }else if(pos == TD_BN_LEFT) {
  739.     *x_max = 0;
  740.     *old_x_begin = 2;
  741.  
  742.     *new_x_begin = *x_max + 2;
  743.     *x_max = *new_x_begin + width;
  744.     return *new_x_begin;
  745.     }
  746.     return 0;
  747. }
  748.  
  749.  
  750. /*****************************************************************************
  751.   FUNCTION : calculate_y_begin
  752.  
  753.   PURPOSE  : calculates the y-coordinate of a plane, where the plane is
  754.              positioned in the display window.
  755.              plane.
  756.  
  757.   NOTES    : 
  758.   RETURNS  : The Y-Position
  759.  
  760.   UPDATE   : 09.02.1993
  761. ******************************************************************************/
  762.  
  763. static int calculate_y_begin(int *absolute_y_max,int *relative_y_max,
  764.                  int *y_offset,int height,int pos)
  765.  
  766. {
  767.     int y_begin;
  768.  
  769.     if(pos == TD_BN_RIGHT) {
  770.     y_begin = *y_offset + 2;         
  771.     *relative_y_max = y_begin + height;
  772.     if(*absolute_y_max < *relative_y_max) {
  773.         *absolute_y_max = *relative_y_max;
  774.     }
  775.     }else if(pos == TD_BN_BELOW) {
  776.     y_begin = *relative_y_max + 2;   
  777.     *relative_y_max = y_begin + height;
  778.     if(*absolute_y_max < *relative_y_max) {
  779.         *absolute_y_max = *relative_y_max;
  780.     }
  781.     }else if(pos == TD_BN_LEFT) {
  782.     *y_offset = *absolute_y_max;
  783.     y_begin = *y_offset + 2;
  784.     *absolute_y_max = y_begin + height;
  785.     *relative_y_max = y_begin + height;
  786.     }
  787.     return y_begin;
  788. }
  789.  
  790.  
  791.  
  792. /*****************************************************************************
  793.   FUNCTION : create_snns_unit
  794.  
  795.   PURPOSE  : creates for every unit of a plane a SNNS default unit.
  796.  
  797.   NOTES    : 
  798.   RETURNS  :
  799.  
  800.   UPDATE   : 09.02.1993
  801. ******************************************************************************/
  802.  
  803. static void create_snns_unit(void)
  804.  
  805. {
  806.     struct PosType unit_pos;
  807.     struct Unit *unit_ptr;
  808.  
  809.     TD_PLANE *TD_PLANE_element = TD_PLANE_first_element; 
  810.     TD_LINK  *TD_LINK_Element;
  811.     int plane_no = 1;
  812.     int lun = 1; /* unit_number within a plane */
  813.     int connection_type;
  814.     int x,y,width,height,unit_no,pos,ret;
  815.     int y_offset=0,relative_y_max=0,absolute_y_max=0,y_begin;
  816.     int x_max=0,old_x_begin=2,new_x_begin,x_begin;
  817.     Bool found;
  818.  
  819.     ret = krui_allocateUnits((*TD_PLANE_last_element).width * 
  820.                              (*TD_PLANE_last_element).height +
  821.                  (*TD_PLANE_last_element).begin-1);
  822.     if(ret != 0){
  823.     ui_tw_errorMessage(krui_error(ret));
  824.     TD_BN_ERROR = 1;
  825.     }
  826.  
  827.     while((! TD_BN_ERROR) && (TD_PLANE_element != NULL)) {
  828.  
  829.     height = (*TD_PLANE_element).height;
  830.     width  = (*TD_PLANE_element).width;
  831.     pos    = (*TD_PLANE_element).pos;
  832.     
  833.     y_begin = calculate_y_begin(&absolute_y_max,&relative_y_max,
  834.                     &y_offset,height,pos);
  835.     x_begin = calculate_x_begin(&new_x_begin,&old_x_begin,
  836.                     &x_max,width,pos);
  837.  
  838.     for(y=0;y<height;y++){
  839.         for(x=0;x<width;x++){
  840.         unit_no = krui_createDefaultUnit();
  841.         if(unit_no<0) ui_checkError(unit_no);
  842.         unit_ptr = kr_getUnitPtr(unit_no);
  843.         ret = krui_setUnitTType(unit_no,(*TD_PLANE_element).type+1);
  844.         if(ret != 0){
  845.             ui_tw_errorMessage(krui_error(ret));
  846.             TD_BN_ERROR = 1;
  847.         }
  848.  
  849.         connection_type = 0;
  850.         found = FALSE;
  851.         TD_LINK_Element = TD_LINK_first_element;
  852.         do {
  853.             if (TD_LINK_Element->TARGET.plane == plane_no) {
  854.             connection_type=TD_LINK_Element->type_of_connection;
  855.             found = TRUE;
  856.             }
  857.             TD_LINK_Element=TD_LINK_Element->next;
  858.         } while ((TD_LINK_Element != NULL) && (!found));
  859.  
  860.         unit_ptr->TD.target_offset = -y*width;
  861.         unit_ptr->TD.source_offset = 0;
  862.  
  863.         if (connection_type == CLUSTER_TO_CLUSTER) { 
  864.             /* recept. field */
  865.             unit_ptr->TD.td_connect_typ = 1;
  866.         }else{
  867.             unit_ptr->TD.td_connect_typ = 0; /* fully connected */
  868.         }
  869.          
  870.         unit_ptr->lun = lun;  /* set logical unitno. */
  871.         unit_ptr->lln = plane_no;  /* set logical layerno.*/ 
  872.  
  873.  
  874.         unit_pos.x = x_begin + x;
  875.         unit_pos.y = y_begin + y;
  876.  
  877.         krui_setUnitPosition(unit_no,&unit_pos);
  878.         lun++;
  879.         }    
  880.     }        
  881.     TD_PLANE_element = (*TD_PLANE_element).next;
  882.     plane_no++;
  883.     lun = 1;   /* reset logical unitnumber */
  884.     } /*while*/
  885. }
  886.  
  887.  
  888.  
  889. /*****************************************************************************
  890.   FUNCTION : make_link
  891.  
  892.   PURPOSE  : creates the links between two planes.
  893.  
  894.   NOTES    : 
  895.   RETURNS  :
  896.  
  897.   UPDATE   : 09.02.1993
  898. ******************************************************************************/
  899.  
  900. static void make_link(TD_PLANE *TD_LINK_source_plane,
  901.               int TD_LINK_source_cluster_x,
  902.               int TD_LINK_source_cluster_y,
  903.               int TD_LINK_source_cluster_width,
  904.               int TD_LINK_source_cluster_height,
  905.               TD_PLANE *TD_LINK_target_plane,
  906.               int TD_LINK_target_cluster_x,
  907.               int TD_LINK_target_cluster_y,
  908.               int TD_LINK_target_cluster_width,
  909.               int TD_LINK_target_cluster_height)
  910.  
  911. {
  912.     int i,j,k,l,ret,target_unit,source_unit;
  913.     int source_features;
  914.     struct Unit *t_ptr;
  915.  
  916.     source_features = TD_LINK_source_plane -> width;
  917.     for (i = 0; i < TD_LINK_target_plane->height; i++)
  918.     for (j = 0; j < TD_LINK_target_plane->width; j++)
  919.     {
  920.         target_unit = TD_LINK_target_plane->begin 
  921.         + (i * TD_LINK_target_plane->width) + j;
  922.         ret = krui_setCurrentUnit(target_unit);
  923.         if(ret != 0)
  924.         {
  925.         ui_tw_errorMessage(krui_error(ret));
  926.         TD_BN_ERROR = 1;
  927.         krui_deleteNet();
  928.         return;
  929.         }
  930.         t_ptr = kr_getUnitPtr(target_unit);
  931.         t_ptr -> TD.source_offset = source_features * i;
  932.     }
  933.     for(i = TD_LINK_target_cluster_y;
  934.     i < TD_LINK_target_cluster_height+TD_LINK_target_cluster_y;
  935.     i++)
  936.     for(j = TD_LINK_target_cluster_x;
  937.         j < TD_LINK_target_cluster_width+TD_LINK_target_cluster_x;
  938.         j++){
  939.  
  940.         target_unit = (*TD_LINK_target_plane).begin + 
  941.         (*TD_LINK_target_plane).width * i + j;
  942.         ret = krui_setCurrentUnit(target_unit);
  943.         if(ret != 0){
  944.         ui_tw_errorMessage(krui_error(ret));
  945.         TD_BN_ERROR = 1;
  946.         krui_deleteNet();
  947.         return;
  948.         }
  949.         for(k = TD_LINK_source_cluster_y;
  950.         k < TD_LINK_source_cluster_height+TD_LINK_source_cluster_y;
  951.         k++)
  952.         for(l = TD_LINK_source_cluster_x;
  953.             l < TD_LINK_source_cluster_width+TD_LINK_source_cluster_x;
  954.             l++){
  955.            
  956.             source_unit = (*TD_LINK_source_plane).begin + 
  957.             (*TD_LINK_source_plane).width * k + l;
  958.             if((ret = krui_createLink(source_unit,0.0)) != 0){
  959.             ui_tw_errorMessage(krui_error(ret));
  960.             TD_BN_ERROR = 1;
  961.             krui_deleteNet();
  962.             return;
  963.             }
  964.         } 
  965.     }             
  966. }
  967.  
  968.  
  969.  
  970. /*****************************************************************************
  971.   FUNCTION : make_move_link
  972.  
  973.   PURPOSE  : while "moving" (see docu)  is possible the function make_link
  974.              is called up.
  975.   NOTES    : 
  976.   RETURNS  :
  977.  
  978.   UPDATE   : 09.02.1993
  979. ******************************************************************************/
  980.  
  981. static void make_move_link(TD_PLANE *TD_LINK_source_plane,
  982.                int TD_LINK_source_cluster_x,
  983.                int LINK_source_cluster_y,
  984.                            int TD_LINK_source_cluster_width,
  985.                int TD_LINK_source_cluster_height,
  986.                            TD_PLANE * TD_LINK_target_plane,
  987.                int TD_LINK_target_cluster_x,
  988.                int LINK_target_cluster_y,
  989.                            int TD_LINK_target_cluster_width,
  990.                int TD_LINK_target_cluster_height,
  991.                            int TD_LINK_source_move_delta_x,
  992.                int TD_LINK_source_move_delta_y,
  993.                            int TD_LINK_target_move_delta_x,
  994.                int TD_LINK_target_move_delta_y)
  995.  
  996. {
  997.  int xs_pivot = TD_LINK_source_cluster_x;
  998.  int xt_pivot = TD_LINK_target_cluster_x;
  999.  
  1000.  do{
  1001.    make_link(TD_LINK_source_plane,TD_LINK_source_cluster_x,
  1002.          TD_LINK_source_cluster_y,TD_LINK_source_cluster_width,
  1003.          TD_LINK_source_cluster_height,TD_LINK_target_plane,
  1004.          TD_LINK_target_cluster_x,TD_LINK_target_cluster_y,
  1005.              TD_LINK_target_cluster_width,TD_LINK_target_cluster_height);
  1006.  }while(! TD_BN_ERROR &&
  1007.     move_p(TD_LINK_source_plane,&TD_LINK_source_cluster_y,
  1008.            &TD_LINK_source_cluster_x,TD_LINK_source_cluster_width,
  1009.            TD_LINK_source_cluster_height,xs_pivot,
  1010.            TD_LINK_source_move_delta_x,TD_LINK_source_move_delta_y) &&
  1011.     move_p(TD_LINK_target_plane,&TD_LINK_target_cluster_y,
  1012.            &TD_LINK_target_cluster_x,TD_LINK_target_cluster_width,
  1013.            TD_LINK_target_cluster_height,xt_pivot,
  1014.            TD_LINK_target_move_delta_x,TD_LINK_target_move_delta_y));
  1015. }
  1016.     
  1017.  
  1018.  
  1019. /*****************************************************************************
  1020.   FUNCTION : move_p
  1021.  
  1022.   PURPOSE  : tests whether the boundaries of a plane are crossed while
  1023.              "moving" (see docu)
  1024.  
  1025.   NOTES    : 
  1026.   RETURNS  : 
  1027.  
  1028.   UPDATE   : 09.02.1993
  1029. ******************************************************************************/
  1030.  
  1031. static int move_p(TD_PLANE *plane_no,int *y,int *x,int width,int height,
  1032.           int x_pivot,int x_step,int y_step)
  1033.  
  1034. {
  1035.     if(x_step > 0 && ((*x)+width+x_step<=(*plane_no).width))
  1036.     (*x)+= x_step;
  1037.     else
  1038.     if(y_step > 0 && ((*y)+height+y_step<=(*plane_no).height))
  1039.         {
  1040.         (*y) += y_step;
  1041.         (*x) = x_pivot;
  1042.         }
  1043.     else
  1044.         return 0;
  1045.  
  1046.     return 1;
  1047. }
  1048.  
  1049.  
  1050. /*****************************************************************************
  1051.   FUNCTION : bn_display_net
  1052.  
  1053.   PURPOSE  : displays the created net in the display window of SNNS.
  1054.  
  1055.   NOTES    : 
  1056.   RETURNS  :
  1057.  
  1058.   UPDATE   : 09.02.1993
  1059. ******************************************************************************/
  1060.  
  1061. static void bn_display_net(void)
  1062.  
  1063. {
  1064.     ui_sel_resetList();
  1065.     ui_net_completeRefresh(ui_currentDisplay,2);
  1066.     ui_stat_displayStatus(ui_gridPosMouse);
  1067.     strcpy(ui_filenameNET,"SNNS_NET");
  1068.     strcpy(ui_filenameSLNET,"SNNS_NET");
  1069.     ui_file_updateShellLabels();
  1070. }
  1071.  
  1072.  
  1073. /*****************************************************************************
  1074.   FUNCTION : read_link_elements
  1075.  
  1076.   PURPOSE  : reads the input datas of the link editor (Edit Link).
  1077.  
  1078.   NOTES    : 
  1079.   RETURNS  : @@@
  1080.  
  1081.   UPDATE   : 09.02.1993
  1082. ******************************************************************************/
  1083.  
  1084. static int read_link_elements(void)
  1085.  
  1086. {
  1087.     TD_LINK_source_plane          = ui_xIntFromAsciiWidget(z10s4);
  1088.     TD_LINK_source_cluster_x      = ui_xIntFromAsciiWidget(z13s4);
  1089.     TD_LINK_source_cluster_y      = 1;
  1090.     TD_LINK_source_cluster_width  = ui_xIntFromAsciiWidget(z15s4);
  1091.     TD_LINK_source_cluster_height = ui_xIntFromAsciiWidget(z16s4);
  1092.  
  1093.     TD_LINK_target_plane          = ui_xIntFromAsciiWidget(z10s5);
  1094.     TD_LINK_target_cluster_x      = ui_xIntFromAsciiWidget(z13s5);
  1095.     TD_LINK_target_cluster_y      = 1;
  1096.     TD_LINK_target_cluster_width  = ui_xIntFromAsciiWidget(z15s5);
  1097.     TD_LINK_target_cluster_height = 1;
  1098.  
  1099.  
  1100.     return correct_link_input();
  1101. }
  1102.  
  1103.  
  1104. /*****************************************************************************
  1105.   FUNCTION : write_current_link
  1106.  
  1107.   PURPOSE  : writes the datas of the current_element to the control part 
  1108.              (Current Link) of the link editor.
  1109.  
  1110.   NOTES    : 
  1111.   RETURNS  :
  1112.  
  1113.   UPDATE   : 09.02.1993
  1114. ******************************************************************************/
  1115.  
  1116. static void write_current_link(void)
  1117.  
  1118. {
  1119.     char buf[10];
  1120.   
  1121.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.plane);
  1122.     ui_xSetLabel(z10s2,td_bn_widget_output(buf));
  1123.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.CLUSTER.x);
  1124.     ui_xSetLabel(z13s2,td_bn_widget_output(buf));
  1125.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.CLUSTER.width);
  1126.     ui_xSetLabel(z15s2,td_bn_widget_output(buf));
  1127.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.CLUSTER.height);
  1128.     ui_xSetLabel(z16s2,td_bn_widget_output(buf));
  1129.  
  1130.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.plane);
  1131.     ui_xSetLabel(z10s3,td_bn_widget_output(buf));
  1132.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.CLUSTER.x);
  1133.     ui_xSetLabel(z13s3,td_bn_widget_output(buf));
  1134.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.CLUSTER.width);
  1135.     ui_xSetLabel(z15s3,td_bn_widget_output(buf));
  1136.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.CLUSTER.height);
  1137.     ui_xSetLabel(z16s3,td_bn_widget_output(buf));
  1138.  
  1139. }
  1140.  
  1141.  
  1142.  
  1143. /*****************************************************************************
  1144.   FUNCTION : clear_current_link
  1145.  
  1146.   PURPOSE  : Deletes the datas standing in Current Link.
  1147.  
  1148.   NOTES    : 
  1149.   RETURNS  :
  1150.  
  1151.   UPDATE   : 09.02.1993
  1152. ******************************************************************************/
  1153.  
  1154. static void clear_current_link(void)
  1155.  
  1156. {
  1157.     ui_xSetLabel(z10s2,"");
  1158.     ui_xSetLabel(z13s2,"");
  1159.     ui_xSetLabel(z15s2,"");
  1160.     ui_xSetLabel(z16s2,"");
  1161.  
  1162.     ui_xSetLabel(z10s3,"");
  1163.     ui_xSetLabel(z13s3,"");
  1164.     ui_xSetLabel(z15s3,"");
  1165.     ui_xSetLabel(z16s3,"");
  1166. }
  1167.  
  1168.  
  1169.  
  1170. /*****************************************************************************
  1171.   FUNCTION : write_current_link_to_editor
  1172.  
  1173.   PURPOSE  : writes the datas of Current Link to Edit Link
  1174.  
  1175.   NOTES    : 
  1176.   RETURNS  :
  1177.  
  1178.   UPDATE   : 09.02.1993
  1179. ******************************************************************************/
  1180.  
  1181. static void write_current_link_to_editor(void)
  1182.  
  1183. {
  1184.  
  1185.     char buf[10];
  1186.  
  1187.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.plane);
  1188.     ui_xSetString(z10s4,td_bn_widget_output(buf));
  1189.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.CLUSTER.x);
  1190.     ui_xSetString(z13s4,td_bn_widget_output(buf));
  1191.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.CLUSTER.width);
  1192.     ui_xSetString(z15s4,td_bn_widget_output(buf));
  1193.     sprintf(buf,"%d",(*TD_LINK_current_element).SOURCE.CLUSTER.height);
  1194.     ui_xSetString(z16s4,td_bn_widget_output(buf));
  1195.  
  1196.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.plane);
  1197.     ui_xSetString(z10s5,td_bn_widget_output(buf));
  1198.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.CLUSTER.x);
  1199.     ui_xSetString(z13s5,td_bn_widget_output(buf));
  1200.     sprintf(buf,"%d",(*TD_LINK_current_element).TARGET.CLUSTER.width);
  1201.     ui_xSetString(z15s5,td_bn_widget_output(buf));
  1202.  
  1203. }
  1204.  
  1205.  
  1206.  
  1207. /*****************************************************************************
  1208.   FUNCTION : clear_edit_link
  1209.  
  1210.   PURPOSE  : Deletes the datas standing in Edit Link.
  1211.  
  1212.   NOTES    : 
  1213.   RETURNS  :
  1214.  
  1215.   UPDATE   : 09.02.1993
  1216. ******************************************************************************/
  1217.  
  1218. static void clear_edit_link(void)
  1219.  
  1220. {
  1221.     ui_xSetString(z10s4,"");
  1222.     ui_xSetString(z13s4,"");
  1223.     ui_xSetString(z15s4,"");
  1224.     ui_xSetString(z16s4,"");
  1225.  
  1226.     ui_xSetString(z10s5,"");
  1227.     ui_xSetString(z13s5,"");
  1228.     ui_xSetString(z15s5,"");
  1229. }
  1230.  
  1231.  
  1232. /*****************************************************************************
  1233.   FUNCTION : enter_link_PROC
  1234.  
  1235.   PURPOSE  : callback function, which enters a link element at the end of the 
  1236.              link list.
  1237.  
  1238.   NOTES    : the link list contains all datas entered by the link editor.
  1239.              Every link element is a struct (see bn_types.c)
  1240.   RETURNS  :
  1241.  
  1242.   UPDATE   : 09.02.1993
  1243. ******************************************************************************/
  1244.  
  1245. static void enter_link_PROC(void)
  1246.  
  1247. {
  1248.     if(read_link_elements()){
  1249.     enter_link();
  1250.     write_current_link();
  1251.     clear_edit_link();
  1252.     }
  1253. }
  1254.  
  1255.  
  1256.  
  1257. /*****************************************************************************
  1258.   FUNCTION : overwrite_link_PROC
  1259.  
  1260.   PURPOSE  : callback function, which overwrites the current link element
  1261.              (Current Link) with the datas of the link editor (Edit Link).
  1262.  
  1263.   NOTES    : 
  1264.   RETURNS  :
  1265.  
  1266.   UPDATE   : 09.02.1993
  1267. ******************************************************************************/
  1268.  
  1269. static void overwrite_link_PROC(void)
  1270.  
  1271. {
  1272.     if(read_link_elements()) {
  1273.     overwrite_link();
  1274.     write_current_link();
  1275.     clear_edit_link();
  1276.     }
  1277. }
  1278.  
  1279.  
  1280.  
  1281. /*****************************************************************************
  1282.   FUNCTION : delete_link_PROC
  1283.  
  1284.   PURPOSE  : callback function, which deletes the Currenrt Link out of
  1285.              the link list.
  1286.  
  1287.   NOTES    : 
  1288.   RETURNS  :
  1289.  
  1290.   UPDATE   : 09.02.1993
  1291. ******************************************************************************/
  1292.  
  1293. static void delete_link_PROC(void)
  1294.  
  1295. {
  1296.     delete_current_link();
  1297.     if(TD_LINK_length == 0) {
  1298.     clear_current_link();
  1299.     }else{
  1300.     write_current_link();
  1301.     }
  1302. }
  1303.  
  1304.  
  1305. /*****************************************************************************
  1306.   FUNCTION : forward_link_PROC
  1307.  
  1308.   PURPOSE  : callback function, which moves forward one list element in the
  1309.              link list.
  1310.  
  1311.   NOTES    : 
  1312.   RETURNS  :
  1313.  
  1314.   UPDATE   : 09.02.1993
  1315. ******************************************************************************/
  1316.  
  1317. static void forward_link_PROC(void)
  1318.  
  1319. {
  1320.     if(forward_link()){
  1321.     write_current_link();
  1322.     }
  1323. }
  1324.  
  1325.  
  1326.  
  1327. /*****************************************************************************
  1328.   FUNCTION : backward_link_PROC
  1329.  
  1330.   PURPOSE  : callback function, which moves backward one list element in the
  1331.              link list.
  1332.  
  1333.   NOTES    : 
  1334.   RETURNS  :
  1335.  
  1336.   UPDATE   : 09.02.1993
  1337. ******************************************************************************/
  1338.  
  1339. static void backward_link_PROC(void)
  1340.  
  1341. {
  1342.     if(backward_link()) {
  1343.     write_current_link();
  1344.     }
  1345. }
  1346.  
  1347.  
  1348.  
  1349. /*****************************************************************************
  1350.   FUNCTION : end_link_PROC
  1351.  
  1352.   PURPOSE  : callback function, which jumps to the end of the link list.
  1353.  
  1354.   NOTES    : 
  1355.   RETURNS  :
  1356.  
  1357.   UPDATE   : 09.02.1993
  1358. ******************************************************************************/
  1359.  
  1360. static void end_link_PROC(void)
  1361.  
  1362. {
  1363.     if(end_link()) {
  1364.     write_current_link();
  1365.     }
  1366. }
  1367.  
  1368.  
  1369.  
  1370. /*****************************************************************************
  1371.   FUNCNCTION : beginning_link_PROC
  1372.  
  1373.   PURPOSE  : callback function, which jumps to the beginning of the link list.
  1374.  
  1375.   NOTES    : 
  1376.   RETURNS  :
  1377.  
  1378.   UPDATE   : 09.02.1993
  1379. ******************************************************************************/
  1380.  
  1381. static void beginning_link_PROC(void)
  1382.  
  1383. {
  1384.     if(beginning_link()) {
  1385.     write_current_link();
  1386.     }
  1387. }
  1388.  
  1389.  
  1390.  
  1391. /*****************************************************************************
  1392.   FUNCNCTION : current_link_to_editor_PROC
  1393.  
  1394.   PURPOSE  : callback function, which writes the Current Link to Edit Link
  1395.  
  1396.   NOTES    : 
  1397.   RETURNS  :
  1398.  
  1399.   UPDATE   : 09.02.1993
  1400. ******************************************************************************/
  1401.  
  1402. static void current_link_to_editor_PROC(void)
  1403.  
  1404. {
  1405.     if(TD_LINK_length != 0) {
  1406.     write_current_link_to_editor();
  1407.     }else{
  1408.     clear_edit_link();
  1409.     }
  1410. }
  1411.  
  1412.  
  1413.  
  1414. /*****************************************************************************
  1415.   FUNCNCTION : correct_link_input
  1416.  
  1417.   PURPOSE  : tests whether the input datas of Edit Link are correct and decides
  1418.              what kind of link (PLANE_TO_PLANE, PLANE_TO_LINK...) we have.
  1419.  
  1420.   NOTES    : 
  1421.   RETURNS  : Correct = 1 ; ERROR = 0
  1422.  
  1423.   UPDATE   : 09.02.1993
  1424. ******************************************************************************/
  1425.  
  1426. static int correct_link_input(void)
  1427.  
  1428. {
  1429.     TD_PLANE *TD_PLANE_source_no,*TD_PLANE_target_no;
  1430.  
  1431.     int link_type;
  1432.     int target_plane=0,
  1433.         source_plane=0;
  1434.     int target_cluster=0,
  1435.         source_cluster=0;
  1436.     int target_unit=0,
  1437.         source_unit=0;
  1438.     int a,b,c,d;
  1439.  
  1440.     TD_PLANE_source_no = get_plane(TD_LINK_source_plane);
  1441.     TD_PLANE_target_no = get_plane(TD_LINK_target_plane);
  1442.  
  1443.     TD_LINK_move = 0;
  1444.  
  1445.     if((TD_PLANE_source_no != TD_PLANE_target_no) &&
  1446.        TD_PLANE_source_no != NULL &&
  1447.        TD_PLANE_target_no != NULL &&
  1448.        (TD_LINK_source_cluster_x + TD_LINK_source_cluster_width  <= 
  1449.     (*TD_PLANE_source_no).width + 1) &&
  1450.        (TD_LINK_source_cluster_y + TD_LINK_source_cluster_height <= 
  1451.     (*TD_PLANE_source_no).height + 1) &&
  1452.        (TD_LINK_source_unit_x <= (*TD_PLANE_source_no).width) &&
  1453.        (TD_LINK_source_unit_y <= (*TD_PLANE_source_no).height) &&
  1454.        (TD_LINK_target_cluster_x + TD_LINK_target_cluster_width  <= 
  1455.     (*TD_PLANE_target_no).width + 1) &&
  1456.        (TD_LINK_target_cluster_y + TD_LINK_target_cluster_height <= 
  1457.     (*TD_PLANE_target_no).height + 1) &&
  1458.        (TD_LINK_target_unit_x <= (*TD_PLANE_target_no).width) &&
  1459.        (TD_LINK_target_unit_y <= (*TD_PLANE_target_no).height)) {
  1460.    
  1461.     target_plane = TD_TARGET_PLANE;
  1462.     source_plane = TD_SOURCE_PLANE;
  1463.  
  1464.     a=b=c=d=0;
  1465.  
  1466.     if(((a=TD_LINK_source_cluster_x) >= 1) &&
  1467.        ((b=TD_LINK_source_cluster_y) >= 1) &&
  1468.        ((c=TD_LINK_source_cluster_width) >= 1) &&
  1469.        ((d=TD_LINK_source_cluster_height) >= 1)) {
  1470.         source_cluster = TD_SOURCE_CLUSTER;
  1471.     }
  1472.  
  1473.     if((! source_cluster) && a+b+c+d) {
  1474.         return 0;
  1475.     }
  1476.  
  1477.     a=b=0;
  1478.  
  1479.     if(((a=TD_LINK_source_unit_x) >= 1) &&
  1480.        ((b=TD_LINK_source_unit_y) >= 1)) {
  1481.         source_unit = TD_SOURCE_UNIT;
  1482.     }
  1483.  
  1484.     if((! source_unit) && a+b) {
  1485.         return 0;
  1486.     }
  1487.  
  1488.     a=b=c=d=0;
  1489.  
  1490.     if(((a=TD_LINK_target_cluster_x) >= 1) &&
  1491.        ((b=TD_LINK_target_cluster_y) >= 1) &&
  1492.        ((c=TD_LINK_target_cluster_width) >= 1) &&
  1493.        ((d=TD_LINK_target_cluster_height) >= 1)) {
  1494.         target_cluster = TD_TARGET_CLUSTER;
  1495.     }
  1496.  
  1497.     if((! target_cluster) && a+b+c+d) {
  1498.         return 0;
  1499.     }
  1500.  
  1501.     a=b=0;
  1502.  
  1503.     if(((a=TD_LINK_target_unit_x) >= 1) &&
  1504.        ((b=TD_LINK_target_unit_y) >= 1)) {
  1505.         target_unit = TD_TARGET_UNIT;
  1506.     }
  1507.  
  1508.     if((! target_unit) && a+b) {
  1509.         return 0;
  1510.     }
  1511.  
  1512.  
  1513.     if(TD_LINK_source_cluster_height !=
  1514.        (*TD_PLANE_source_no).height - (*TD_PLANE_target_no).height + 1){
  1515.         return 0;
  1516.     }
  1517.  
  1518.  
  1519.     link_type =  target_plane+source_plane+
  1520.                  target_cluster+source_cluster+
  1521.              target_unit+source_unit;
  1522.  
  1523.     if(link_type == PLANE_TO_PLANE){
  1524.        TD_LINK_source_cluster_height = (*TD_PLANE_source_no).height;
  1525.         }
  1526.  
  1527.     if((link_type == PLANE_TO_PLANE) ||
  1528.        (link_type == PLANE_TO_CLUSTER) ||
  1529.        (link_type == PLANE_TO_UNIT) ||
  1530.        (link_type == CLUSTER_TO_PLANE) ||
  1531.        (link_type == CLUSTER_TO_CLUSTER) ||
  1532.        (link_type == CLUSTER_TO_UNIT) ||
  1533.        (link_type == UNIT_TO_PLANE) ||
  1534.        (link_type == UNIT_TO_CLUSTER) ||
  1535.        (link_type == UNIT_TO_UNIT)) {
  1536.  
  1537.         TD_LINK_type_of_connection = link_type;
  1538.  
  1539.         if((TD_LINK_source_move_delta_x || TD_LINK_source_move_delta_y ||
  1540.         TD_LINK_target_move_delta_x || TD_LINK_target_move_delta_y) &&
  1541.            ((link_type == CLUSTER_TO_CLUSTER) ||
  1542.         (link_type == CLUSTER_TO_UNIT)    ||
  1543.         (link_type == UNIT_TO_CLUSTER)    ||
  1544.         (link_type == UNIT_TO_UNIT))) {
  1545.         TD_LINK_move = 1;
  1546.         }
  1547.         else {
  1548.         TD_LINK_source_move_delta_x = 
  1549.             TD_LINK_source_move_delta_y = 
  1550.             TD_LINK_target_move_delta_x = 
  1551.             TD_LINK_target_move_delta_y = 0;
  1552.         }
  1553.         return 1;
  1554.     }            /* if */
  1555.     }
  1556.     return 0;
  1557. }
  1558.  
  1559.  
  1560. /*****************************************************************************
  1561.   FUNCTION : enter_link
  1562.  
  1563.   PURPOSE  : enters a link element at the end of the link list.
  1564.  
  1565.   NOTES    : 
  1566.   RETURNS  :
  1567.  
  1568.   UPDATE   : 09.02.1993
  1569. ******************************************************************************/
  1570.  
  1571. static void enter_link(void)
  1572.  
  1573. {
  1574.     TD_LINK *TD_LINK_element;
  1575.  
  1576.     TD_LINK_element = (TD_LINK *)malloc(sizeof(TD_LINK)); 
  1577.  
  1578.     (*TD_LINK_element).SOURCE.plane          = TD_LINK_source_plane;
  1579.     (*TD_LINK_element).SOURCE.CLUSTER.x      = TD_LINK_source_cluster_x;
  1580.     (*TD_LINK_element).SOURCE.CLUSTER.y      = TD_LINK_source_cluster_y;
  1581.     (*TD_LINK_element).SOURCE.CLUSTER.width  = TD_LINK_source_cluster_width;
  1582.     (*TD_LINK_element).SOURCE.CLUSTER.height = TD_LINK_source_cluster_height;
  1583.     (*TD_LINK_element).SOURCE.UNIT.x         = TD_LINK_source_unit_x;
  1584.     (*TD_LINK_element).SOURCE.UNIT.y         = TD_LINK_source_unit_y;
  1585.     (*TD_LINK_element).SOURCE.MOVE.delta_x   = TD_LINK_source_move_delta_x;
  1586.     (*TD_LINK_element).SOURCE.MOVE.delta_y   = TD_LINK_source_move_delta_y;
  1587.  
  1588.     (*TD_LINK_element).TARGET.plane          = TD_LINK_target_plane;
  1589.     (*TD_LINK_element).TARGET.CLUSTER.x      = TD_LINK_target_cluster_x;
  1590.     (*TD_LINK_element).TARGET.CLUSTER.y      = TD_LINK_target_cluster_y;
  1591.     (*TD_LINK_element).TARGET.CLUSTER.width  = TD_LINK_target_cluster_width;
  1592.     (*TD_LINK_element).TARGET.CLUSTER.height = TD_LINK_target_cluster_height;
  1593.     (*TD_LINK_element).TARGET.UNIT.x         = TD_LINK_target_unit_x;
  1594.     (*TD_LINK_element).TARGET.UNIT.y         = TD_LINK_target_unit_y;
  1595.     (*TD_LINK_element).TARGET.MOVE.delta_x   = TD_LINK_target_move_delta_x;
  1596.     (*TD_LINK_element).TARGET.MOVE.delta_y   = TD_LINK_target_move_delta_y;
  1597.  
  1598.     (*TD_LINK_element).move                  = TD_LINK_move;
  1599.     (*TD_LINK_element).type_of_connection    = TD_LINK_type_of_connection;
  1600.  
  1601.     (*TD_LINK_element).next   = NULL;
  1602.     (*TD_LINK_element).before = TD_LINK_last_element;
  1603.    
  1604.     if(TD_LINK_last_element != NULL) {
  1605.     (*TD_LINK_last_element).next = TD_LINK_element;
  1606.     }
  1607.  
  1608.     if(TD_LINK_first_element == NULL) {
  1609.     TD_LINK_first_element = TD_LINK_element;
  1610.     }
  1611.  
  1612.     TD_LINK_last_element = TD_LINK_element;
  1613.     TD_LINK_current_element = TD_LINK_last_element;
  1614.    
  1615.     TD_LINK_length++;
  1616.  
  1617. }
  1618.  
  1619.  
  1620.  
  1621.  
  1622. /*****************************************************************************
  1623.   FUNCTION : overwrite_link
  1624.  
  1625.   PURPOSE  : overwrites the current link element (Current Link) with the 
  1626.              datas of the link editor (Edit Link).
  1627.  
  1628.   NOTES    : 
  1629.   RETURNS  :
  1630.  
  1631.   UPDATE   : 09.02.1993
  1632. ******************************************************************************/
  1633.  
  1634. static void overwrite_link(void)
  1635.  
  1636. {
  1637.     if(TD_LINK_length == 0) {
  1638.     enter_link();
  1639.     }else{
  1640.     (*TD_LINK_current_element).SOURCE.plane = TD_LINK_source_plane;
  1641.     (*TD_LINK_current_element).SOURCE.CLUSTER.x = TD_LINK_source_cluster_x;
  1642.     (*TD_LINK_current_element).SOURCE.CLUSTER.y = TD_LINK_source_cluster_y;
  1643.     (*TD_LINK_current_element).SOURCE.CLUSTER.width = 
  1644.         TD_LINK_source_cluster_width;
  1645.     (*TD_LINK_current_element).SOURCE.CLUSTER.height = 
  1646.         TD_LINK_source_cluster_height;
  1647.     (*TD_LINK_current_element).SOURCE.UNIT.x = TD_LINK_source_unit_x;
  1648.     (*TD_LINK_current_element).SOURCE.UNIT.y = TD_LINK_source_unit_y;
  1649.     (*TD_LINK_current_element).SOURCE.MOVE.delta_x =
  1650.         TD_LINK_source_move_delta_x;
  1651.     (*TD_LINK_current_element).SOURCE.MOVE.delta_y = 
  1652.         TD_LINK_source_move_delta_y;
  1653.   
  1654.     (*TD_LINK_current_element).TARGET.plane = TD_LINK_target_plane;
  1655.     (*TD_LINK_current_element).TARGET.CLUSTER.x = TD_LINK_target_cluster_x;
  1656.     (*TD_LINK_current_element).TARGET.CLUSTER.y = TD_LINK_target_cluster_y;
  1657.     (*TD_LINK_current_element).TARGET.CLUSTER.width = 
  1658.         TD_LINK_target_cluster_width;
  1659.     (*TD_LINK_current_element).TARGET.CLUSTER.height = 
  1660.         TD_LINK_target_cluster_height;
  1661.     (*TD_LINK_current_element).TARGET.UNIT.x = TD_LINK_target_unit_x;
  1662.     (*TD_LINK_current_element).TARGET.UNIT.y = TD_LINK_target_unit_y;
  1663.     (*TD_LINK_current_element).TARGET.MOVE.delta_x = 
  1664.         TD_LINK_target_move_delta_x;
  1665.     (*TD_LINK_current_element).TARGET.MOVE.delta_y = 
  1666.         TD_LINK_target_move_delta_y;
  1667.  
  1668.     (*TD_LINK_current_element).move = TD_LINK_move;
  1669.     (*TD_LINK_current_element).type_of_connection = 
  1670.         TD_LINK_type_of_connection;
  1671.  
  1672.  
  1673.     }        
  1674. }        
  1675.  
  1676.  
  1677.  
  1678. /*****************************************************************************
  1679.   FUNCTION : delete_current_link
  1680.  
  1681.   PURPOSE  : deletes  Currenrt Link out of the link list.
  1682.  
  1683.   NOTES    : 
  1684.   RETURNS  :
  1685.  
  1686.   UPDATE   : 09.02.1993
  1687. ******************************************************************************/
  1688.  
  1689. static void delete_current_link(void)
  1690.  
  1691. {
  1692.     TD_LINK *TD_LINK_element;
  1693.  
  1694.     TD_LINK_element = TD_LINK_current_element;
  1695.  
  1696.     /* Delete the element "TD_LINK_element" out of the plane-list */
  1697.  
  1698.     if(TD_LINK_length != 0) {
  1699.     if((*TD_LINK_element).before != NULL) {
  1700.         (*(*TD_LINK_element).before).next = (*TD_LINK_element).next;
  1701.     }
  1702.     if((*TD_LINK_element).next != NULL) {
  1703.         (*(*TD_LINK_element).next).before = (*TD_LINK_element).before;
  1704.     }
  1705.  
  1706.     TD_LINK_length--;
  1707.  
  1708.     /* Update the three pointers 
  1709.        TD_LINK_current_element,
  1710.        TD_LINK_first_element,
  1711.        TD_LINK_last_element.
  1712.        */
  1713.  
  1714.     if(TD_LINK_length == 0){
  1715.         TD_LINK_current_element = NULL;
  1716.         TD_LINK_first_element   = NULL;
  1717.         TD_LINK_last_element    = NULL;
  1718.     }else if((*TD_LINK_element).next == NULL) {
  1719.         TD_LINK_current_element = (*TD_LINK_element).before;
  1720.         TD_LINK_last_element    = TD_LINK_current_element;
  1721.     }else if((*TD_LINK_element).before == NULL) {
  1722.         TD_LINK_current_element = (*TD_LINK_element).next;
  1723.         TD_LINK_first_element   = TD_LINK_current_element;
  1724.     }else{
  1725.         TD_LINK_current_element = (*TD_LINK_element).next;
  1726.     }  
  1727.  
  1728.     free(TD_LINK_element);
  1729.     }
  1730. }
  1731.  
  1732.  
  1733.  
  1734.  
  1735. /*****************************************************************************
  1736.   FUNCTION : get_links_and_delete_them(plane_no)
  1737.  
  1738.   PURPOSE  : deletes all the links which are connected with the plane 
  1739.              "plane_no"
  1740.  
  1741.   NOTES    : 
  1742.   RETURNS  :
  1743.  
  1744.   UPDATE   : 09.02.1993
  1745. ******************************************************************************/
  1746.  
  1747. static void get_links_and_delete_them(int plane_no)
  1748.  
  1749. {
  1750.     TD_LINK *TD_LINK_element = TD_LINK_first_element;
  1751.  
  1752.     while(TD_LINK_element != NULL) {
  1753.     if(((*TD_LINK_element).SOURCE.plane != plane_no) &&
  1754.        ((*TD_LINK_element).TARGET.plane != plane_no)) {
  1755.         TD_LINK_element = (*TD_LINK_element).next;
  1756.     }else {
  1757.         TD_LINK_current_element = TD_LINK_element;
  1758.         TD_LINK_element = (*TD_LINK_element).next;
  1759.         delete_current_link();
  1760.     }
  1761.     }        
  1762. }
  1763.  
  1764.  
  1765.  
  1766.  
  1767. /*****************************************************************************
  1768.   FUNCTION : forward_link
  1769.  
  1770.   PURPOSE  : moves forward one list element in the link list.
  1771.  
  1772.   NOTES    : 
  1773.   RETURNS  :  Error = 0 ; Succes = 1
  1774.  
  1775.   UPDATE   : 09.02.1993
  1776. ******************************************************************************/
  1777.  
  1778. static int forward_link(void)
  1779.  
  1780. {
  1781.     if(TD_LINK_length != 0) {
  1782.     if((*TD_LINK_current_element).next != NULL) {
  1783.         TD_LINK_current_element = (*TD_LINK_current_element).next;
  1784.     }
  1785.     return 1;
  1786.     }
  1787.     return 0;
  1788. }
  1789.  
  1790.  
  1791.  
  1792.  
  1793. /*****************************************************************************
  1794.   FUNCTION : backward_link
  1795.  
  1796.   PURPOSE  : moves backward one list element in the link list.
  1797.   NOTES    : 
  1798.   RETURNS  : Error = 0 ; Succes = 1
  1799.  
  1800.   UPDATE   : 09.02.1993
  1801. ******************************************************************************/
  1802.  
  1803. static int backward_link(void)
  1804.  
  1805. {
  1806.     if(TD_LINK_length != 0) {
  1807.     if((*TD_LINK_current_element).before != NULL) {
  1808.         TD_LINK_current_element = (*TD_LINK_current_element).before;
  1809.     }
  1810.     return 1;
  1811.     }
  1812.     return 0;
  1813. }
  1814.  
  1815.  
  1816.  
  1817. /*****************************************************************************
  1818.   FUNCTION : beginning_link
  1819.  
  1820.   PURPOSE  : jumps to the beginning of the link list.
  1821.  
  1822.   NOTES    : 
  1823.   RETURNS  : Error = 0 ; Succes = 1
  1824.  
  1825.   UPDATE   : 09.02.1993
  1826. ******************************************************************************/
  1827.  
  1828. static int beginning_link(void)
  1829.  
  1830. {
  1831.     if(TD_LINK_length != 0){
  1832.     TD_LINK_current_element = TD_LINK_first_element;
  1833.     return 1;
  1834.     }
  1835.     return 0;
  1836. }
  1837.  
  1838.  
  1839.  
  1840. /*****************************************************************************
  1841.   FUNCTION : end_link
  1842.  
  1843.   PURPOSE  : jumps to the end of the link list.
  1844.   NOTES    : 
  1845.   RETURNS  : Error = 0 ; Succes = 1
  1846.  
  1847.   UPDATE   : 09.02.1993
  1848. ******************************************************************************/
  1849.  
  1850. static int end_link(void)
  1851.  
  1852. {
  1853.     if(TD_LINK_length != 0) {
  1854.     TD_LINK_current_element = TD_LINK_last_element;
  1855.     return 1;
  1856.     }
  1857.     return 0;
  1858. }
  1859.  
  1860.  
  1861.  
  1862. /*****************************************************************************
  1863.   FUNCTION : read_plane_elements
  1864.  
  1865.   PURPOSE  : reads the input datas of the plane editor (Edit Plane).
  1866.  
  1867.   NOTES    : 
  1868.   RETURNS  :  Error = 0 ; Succes = 1
  1869.  
  1870.   UPDATE   : 09.02.1993
  1871. ******************************************************************************/
  1872.  
  1873. static int read_plane_elements(void)
  1874.  
  1875. {
  1876.     TD_PLANE_width = ui_xIntFromAsciiWidget(z4s3);
  1877.     TD_PLANE_height = ui_xIntFromAsciiWidget(z5s3);
  1878.     if((TD_PLANE_width > 0) && (TD_PLANE_height > 0)) {
  1879.     return 1;
  1880.     }else{
  1881.     return 0;
  1882.     }
  1883. }
  1884.   
  1885.  
  1886. /*****************************************************************************
  1887.   FUNCTION : write_current_plane
  1888.  
  1889.   PURPOSE  : writes the datas of the current_element to the control part 
  1890.              (Current Plane) of the plane editor.
  1891.  
  1892.   NOTES    : 
  1893.   RETURNS  : 
  1894.  
  1895.   UPDATE   : 09.02.1993
  1896. ******************************************************************************/
  1897.  
  1898. static void write_current_plane(void)
  1899.  
  1900. {
  1901.     char buf[10];
  1902.  
  1903.     sprintf(buf,"%d",TD_PLANE_no);
  1904.     ui_xSetLabel(z2s2,td_bn_widget_output(buf));
  1905.     ui_xSetLabel(z3s2,td_plane_type[(*TD_PLANE_current_element).type]);
  1906.     sprintf(buf,"%d",(*TD_PLANE_current_element).width);
  1907.     ui_xSetLabel(z4s2,td_bn_widget_output(buf));
  1908.     sprintf(buf,"%d",(*TD_PLANE_current_element).height);
  1909.     ui_xSetLabel(z5s2,td_bn_widget_output(buf));
  1910.     sprintf(buf,"%d",0);
  1911.     ui_xSetLabel(z6s2,td_bn_widget_output(buf));
  1912.     ui_xSetLabel(z7s2,td_plane_pos[(*TD_PLANE_current_element).pos]);
  1913. }
  1914.  
  1915.  
  1916.  
  1917. /*****************************************************************************
  1918.   FUNCTION : clear_current_plane
  1919.  
  1920.   PURPOSE  : Deletes the datas standing in Current Plane.
  1921.  
  1922.   NOTES    : 
  1923.   RETURNS  :
  1924.  
  1925.   UPDATE   : 09.02.1993
  1926. ******************************************************************************/
  1927.  
  1928. static void clear_current_plane(void)
  1929.  
  1930. {
  1931.     ui_xSetLabel(z2s2,"");
  1932.     ui_xSetLabel(z3s2,"");
  1933.     ui_xSetLabel(z4s2,"");
  1934.     ui_xSetLabel(z5s2,"");
  1935.     ui_xSetLabel(z6s2,"");
  1936.     ui_xSetLabel(z7s2,"");
  1937. }
  1938.  
  1939.  
  1940.  
  1941. /*****************************************************************************
  1942.   FUNCTION : write_current_plane_to_editor
  1943.  
  1944.   PURPOSE  : writes the datas of Current Plane to Edit Plane
  1945.  
  1946.   NOTES    : 
  1947.   RETURNS  :
  1948.  
  1949.   UPDATE   : 09.02.1993
  1950. ******************************************************************************/
  1951.  
  1952. static void write_current_plane_to_editor(void)
  1953.  
  1954. {
  1955.     char buf[10];
  1956.  
  1957.     TD_PLANE_type = (*TD_PLANE_current_element).type;
  1958.     ui_xSetLabel(z3s3,td_plane_type[TD_PLANE_type]);
  1959.     sprintf(buf,"%d",(*TD_PLANE_current_element).width);
  1960.     ui_xSetString(z4s3,td_bn_widget_output(buf));
  1961.     sprintf(buf,"%d",(*TD_PLANE_current_element).height);
  1962.     ui_xSetString(z5s3,td_bn_widget_output(buf));
  1963.     sprintf(buf,"%d",0);
  1964.     ui_xSetString(z6s3,td_bn_widget_output(buf));
  1965.     TD_PLANE_pos = (*TD_PLANE_current_element).pos;
  1966.     ui_xSetLabel(z7s3,td_plane_pos[TD_PLANE_pos]);
  1967. }
  1968.  
  1969.  
  1970.  
  1971. /*****************************************************************************
  1972.   FUNCTION : clear_edit_plane
  1973.  
  1974.   PURPOSE  : Deletes the datas standing in Edit Link.
  1975.  
  1976.   NOTES    : 
  1977.   RETURNS  :
  1978.  
  1979.   UPDATE   : 09.02.1993
  1980. ******************************************************************************/
  1981.  
  1982. static void clear_edit_plane(void)
  1983.  
  1984. {
  1985.     ui_xSetString(z4s3,"");
  1986.     ui_xSetString(z5s3,"");
  1987.     ui_xSetString(z6s3,"");
  1988.  
  1989.  
  1990.  
  1991.  
  1992. /*****************************************************************************
  1993.   FUNCTION : cancel_net_PROC
  1994.  
  1995.   PURPOSE  : callback function, which deletes all the datas in the link 
  1996.              editor and in the plane editor.
  1997.  
  1998.   NOTES    : 
  1999.   RETURNS  :
  2000.  
  2001.   UPDATE   : 09.02.1993
  2002. ******************************************************************************/
  2003.  
  2004. static void cancel_net_PROC(void)
  2005.  
  2006. {
  2007.     while(TD_PLANE_length){
  2008.     delete_current_plane();
  2009.     }
  2010.     clear_current_plane();
  2011.     clear_current_link();
  2012. }
  2013.  
  2014.  
  2015.  
  2016. /*****************************************************************************
  2017.   FUNCTION : enter_plane_PROC
  2018.  
  2019.   PURPOSE  : callback function, which enters a plane element at the end of the 
  2020.              plane list.
  2021.  
  2022.   NOTES    : the plane list contains all datas entered by the plane editor.
  2023.              Every plane element is a struct (see bn_types.c)
  2024.   RETURNS  :
  2025.  
  2026.   UPDATE   : 09.02.1993
  2027. ******************************************************************************/
  2028.  
  2029. static void enter_plane_PROC(void)
  2030.  
  2031. {
  2032.     if(read_plane_elements()){
  2033.     enter_plane();
  2034.     write_current_plane();
  2035.     clear_edit_plane();
  2036.     }
  2037. }
  2038.  
  2039.  
  2040.  
  2041. /*****************************************************************************
  2042.   FUNCTION : insert_plane_PROC
  2043.  
  2044.   PURPOSE  : callback function, which inserts the the input datas of the
  2045.              plane editor (Edit Plane) in front of Current Plane.
  2046.  
  2047.   NOTES    : 
  2048.   RETURNS  :
  2049.  
  2050.   UPDATE   : 09.02.1993
  2051. ******************************************************************************/
  2052.  
  2053. static void insert_plane_PROC(void)
  2054.  
  2055. {
  2056.     if(read_plane_elements()) {
  2057.     insert_plane();
  2058.     write_current_plane();
  2059.     clear_edit_plane();
  2060.     if(TD_LINK_length == 0) {
  2061.         clear_current_link();
  2062.     }else{
  2063.         write_current_link();
  2064.     }
  2065.     }
  2066. }
  2067.  
  2068.  
  2069.  
  2070. /*****************************************************************************
  2071.   FUNCTION : overwrite_plane_PROC
  2072.  
  2073.   PURPOSE  : callback function, which overwrites the current plane element
  2074.              (Current Plane) with the datas of the plane editor (Edit plane).
  2075.  
  2076.   NOTES    : 
  2077.   RETURNS  :
  2078.  
  2079.   UPDATE   : 20.12.1991
  2080. ******************************************************************************/
  2081.  
  2082. static void overwrite_plane_PROC(void)
  2083.  
  2084. {
  2085.     if(read_plane_elements()) {
  2086.     overwrite_plane();
  2087.     write_current_plane();
  2088.     clear_edit_plane();
  2089.     if(TD_LINK_length == 0) {
  2090.         clear_current_link();
  2091.     }else{
  2092.         write_current_link();
  2093.     }
  2094.     }
  2095. }
  2096.  
  2097.  
  2098.  
  2099. /*****************************************************************************
  2100.   FUNCTION : delete_plane_PROC
  2101.  
  2102.   PURPOSE  : callback function, which deletes the Currenrt Plane out of
  2103.              the plane list.
  2104.  
  2105.   NOTES    : 
  2106.   RETURNS  :
  2107.  
  2108.   UPDATE   : 09.02.1993
  2109. ******************************************************************************/
  2110.  
  2111. static void delete_plane_PROC(void)
  2112.  
  2113. {
  2114.     delete_current_plane();
  2115.     if(TD_PLANE_length == 0) {
  2116.     clear_current_plane();
  2117.     }else{
  2118.     write_current_plane();
  2119.     }
  2120.     if(TD_LINK_length == 0) {
  2121.     clear_current_link();
  2122.     }else{
  2123.     write_current_link();
  2124.     }
  2125. }
  2126.  
  2127.  
  2128.  
  2129. /*****************************************************************************
  2130.   FUNCTION : forward_plane_PROC
  2131.  
  2132.   PURPOSE  : callback function, which moves forward one list element in the
  2133.              plane list.
  2134.  
  2135.   NOTES    : 
  2136.   RETURNS  :
  2137.  
  2138.   UPDATE   : 09.02.1993
  2139. ******************************************************************************/
  2140.  
  2141. static void forward_plane_PROC(void)
  2142.  
  2143. {
  2144.     if(forward_plane()){
  2145.     write_current_plane();
  2146.     }
  2147. }
  2148.  
  2149.  
  2150.  
  2151. /*****************************************************************************
  2152.   FUNCTION : backward_plane_PROC
  2153.  
  2154.   PURPOSE  : callback function, which moves backward one list element in the
  2155.              plane list.
  2156.  
  2157.   NOTES    : 
  2158.   RETURNS  :
  2159.  
  2160.   UPDATE   : 09.02.1993
  2161. ******************************************************************************/
  2162.  
  2163. static void backward_plane_PROC(void)
  2164.  
  2165. {
  2166.     if(backward_plane()) {
  2167.     write_current_plane();
  2168.     }
  2169. }
  2170.  
  2171.  
  2172.  
  2173. /*****************************************************************************
  2174.   FUNCTION : end_plane_PROC
  2175.  
  2176.   PURPOSE  : callback function, which jumps to the end of the plane list.
  2177.  
  2178.   NOTES    : 
  2179.   RETURNS  :
  2180.  
  2181.   UPDATE   : 09.02.1993
  2182. ******************************************************************************/
  2183.  
  2184. static void end_plane_PROC(void)
  2185.  
  2186. {
  2187.     if(end_plane()) {
  2188.     write_current_plane();
  2189.     }
  2190. }
  2191.  
  2192.  
  2193.  
  2194. /*****************************************************************************
  2195.   FUNCTION : beginning_plane_PROC
  2196.  
  2197.   PURPOSE  : callback function, which jumps to the beginning of the plane list.
  2198.  
  2199.   NOTES    : 
  2200.   RETURNS  :
  2201.  
  2202.   UPDATE   : 09.02.1993
  2203. ******************************************************************************/
  2204.  
  2205. static void beginning_plane_PROC(void)
  2206.  
  2207. {
  2208.     if(beginning_plane()) {
  2209.     write_current_plane();
  2210.     }
  2211. }
  2212.  
  2213.  
  2214.  
  2215. /*****************************************************************************
  2216.   FUNCNCTION : pos_PROC
  2217.  
  2218.   PURPOSE  : callback function, which defines the position of the plane in the
  2219.              display window.
  2220.  
  2221.   NOTES    : 
  2222.   RETURNS  :
  2223.  
  2224.   UPDATE   : 09.02.1993
  2225. ******************************************************************************/
  2226.  
  2227. static void pos_PROC(void)
  2228.  
  2229. {
  2230.     if(TD_PLANE_pos == TD_BN_RIGHT) {
  2231.     TD_PLANE_pos = TD_BN_BELOW;
  2232.     }else if(TD_PLANE_pos == TD_BN_BELOW) {
  2233.     TD_PLANE_pos = TD_BN_LEFT;
  2234.     }else{
  2235.     TD_PLANE_pos = TD_BN_RIGHT;
  2236.     }
  2237.     ui_xSetLabel(z7s3,td_plane_pos[TD_PLANE_pos]);
  2238. }
  2239.  
  2240.  
  2241.  
  2242. /*****************************************************************************
  2243.   FUNCNCTION : current_plane_to_editor_PROC
  2244.  
  2245.   PURPOSE  : callback function, which writes the Current Plane to Edit Plane
  2246.  
  2247.   NOTES    : 
  2248.   RETURNS  :
  2249.  
  2250.   UPDATE   : 09.02.1993
  2251. ******************************************************************************/
  2252.  
  2253. static void current_plane_to_editor_PROC(void)
  2254.  
  2255. {
  2256.     if(TD_PLANE_length != 0) {
  2257.     write_current_plane_to_editor();
  2258.     }else{
  2259.     clear_edit_plane();
  2260.     }
  2261. }
  2262.  
  2263.  
  2264.  
  2265. /*****************************************************************************
  2266.   FUNCNCTION : type_PROC
  2267.  
  2268.   PURPOSE  : callback function, which defines the unit type of a plane.
  2269.  
  2270.   NOTES    : 
  2271.   RETURNS  :
  2272.  
  2273.   UPDATE   : 09.02.1993
  2274. ******************************************************************************/
  2275.  
  2276. static void type_PROC(void)
  2277.  
  2278. {
  2279.     switch(TD_PLANE_type){
  2280.       case TD_BN_INPUT : {TD_PLANE_type = TD_BN_HIDDEN; break;}
  2281.       case TD_BN_HIDDEN: {TD_PLANE_type = TD_BN_OUTPUT; break;}
  2282.       case TD_BN_OUTPUT: {TD_PLANE_type = TD_BN_INPUT ; break;}
  2283.     }
  2284.     ui_xSetLabel(z3s3,td_plane_type[TD_PLANE_type]);
  2285. }
  2286.  
  2287.  
  2288.  
  2289. /*****************************************************************************
  2290.   FUNCTION : enter_plane
  2291.  
  2292.   PURPOSE  : enters a plane element at the end of the plane list.
  2293.  
  2294.   NOTES    : 
  2295.   RETURNS  :
  2296.  
  2297.   UPDATE   : 09.02.1993
  2298. ******************************************************************************/
  2299.  
  2300. static void enter_plane(void)
  2301.  
  2302. {
  2303.     TD_PLANE *TD_PLANE_element;
  2304.  
  2305.     TD_PLANE_element = (TD_PLANE *)malloc(sizeof(TD_PLANE));
  2306.     (*TD_PLANE_element).width  = TD_PLANE_width;    
  2307.     (*TD_PLANE_element).height = TD_PLANE_height;
  2308.     (*TD_PLANE_element).pos    = TD_PLANE_pos;
  2309.     (*TD_PLANE_element).type   = TD_PLANE_type;  
  2310.     (*TD_PLANE_element).next   = NULL;                            
  2311.     (*TD_PLANE_element).before = TD_PLANE_last_element;         
  2312.  
  2313.     if(TD_PLANE_last_element != NULL) {
  2314.     (*TD_PLANE_last_element).next = TD_PLANE_element;
  2315.     }
  2316.  
  2317.     if(TD_PLANE_first_element == NULL) {
  2318.     TD_PLANE_first_element = TD_PLANE_element;
  2319.     }
  2320.  
  2321.     TD_PLANE_last_element = TD_PLANE_element;
  2322.     TD_PLANE_current_element = TD_PLANE_last_element;
  2323.  
  2324.     TD_PLANE_no = ++TD_PLANE_length;
  2325.  
  2326. }    
  2327.  
  2328.  
  2329.  
  2330. /*****************************************************************************
  2331.   FUNCTION : insert_plane
  2332.  
  2333.   PURPOSE  : inserts the the input datas of the plane editor (Edit Plane) in 
  2334.              front of Current Plane.
  2335.  
  2336.   NOTES    : 
  2337.   RETURNS  :
  2338.  
  2339.   UPDATE   : 09.02.1993
  2340. ******************************************************************************/
  2341.  
  2342. static void insert_plane(void)
  2343.  
  2344. {
  2345.     TD_PLANE *TD_PLANE_element;
  2346.  
  2347.     if(TD_PLANE_length == 0) {
  2348.     enter_plane();
  2349.     }else{
  2350.     TD_PLANE_element = (TD_PLANE *)malloc(sizeof(TD_PLANE));
  2351.    
  2352.     (*TD_PLANE_element).width  = TD_PLANE_width;                   
  2353.     (*TD_PLANE_element).height = TD_PLANE_height;
  2354.     (*TD_PLANE_element).pos    = TD_PLANE_pos;
  2355.     (*TD_PLANE_element).type   = TD_PLANE_type;                         
  2356.     (*TD_PLANE_element).next   = TD_PLANE_current_element;          
  2357.     (*TD_PLANE_element).before = (*TD_PLANE_current_element).before;
  2358.  
  2359.     if((*TD_PLANE_current_element).before != 0) {
  2360.         (*(*TD_PLANE_current_element).before).next = TD_PLANE_element;
  2361.     }
  2362.     (*TD_PLANE_current_element).before = TD_PLANE_element;         
  2363.  
  2364.     TD_PLANE_current_element = TD_PLANE_element;
  2365.    
  2366.     if((*TD_PLANE_element).before == NULL) {
  2367.         TD_PLANE_first_element = TD_PLANE_element;
  2368.     } 
  2369.  
  2370.     TD_PLANE_length++;
  2371.  
  2372.     TD_LINK_current_element = TD_LINK_first_element; 
  2373.  
  2374.     while(TD_LINK_current_element) {
  2375.         if((*TD_LINK_current_element).SOURCE.plane >= TD_PLANE_no) {
  2376.         (*TD_LINK_current_element).SOURCE.plane++;
  2377.         }
  2378.         if((*TD_LINK_current_element).TARGET.plane >= TD_PLANE_no) {
  2379.         (*TD_LINK_current_element).TARGET.plane++;
  2380.         }
  2381.         TD_LINK_current_element = (*TD_LINK_current_element).next;
  2382.     }
  2383.  
  2384.     TD_LINK_current_element = TD_LINK_last_element;
  2385.  
  2386.     }
  2387.  
  2388. }
  2389.  
  2390.  
  2391.  
  2392. /*****************************************************************************
  2393.   FUNCTION : overwrite_plane
  2394.  
  2395.   PURPOSE  : overwrites the current plane element (Current Plane) with the 
  2396.              datas of the plane editor (Edit Plane).
  2397.  
  2398.   NOTES    : 
  2399.   RETURNS  :
  2400.  
  2401.   UPDATE   : 09.02.1993
  2402. ******************************************************************************/
  2403.  
  2404. static void overwrite_plane(void)
  2405.  
  2406. {
  2407.     if(TD_PLANE_length == 0) {
  2408.     enter_plane();
  2409.     }else{
  2410.     (*TD_PLANE_current_element).width  = TD_PLANE_width;
  2411.     (*TD_PLANE_current_element).height = TD_PLANE_height;
  2412.     (*TD_PLANE_current_element).pos    = TD_PLANE_pos;
  2413.     (*TD_PLANE_current_element).type   = TD_PLANE_type;
  2414.  
  2415.     get_links_and_delete_them(TD_PLANE_no);
  2416.  
  2417.     TD_LINK_current_element = TD_LINK_first_element;
  2418.  
  2419.     }
  2420.  
  2421. }
  2422.  
  2423.  
  2424.  
  2425. /*****************************************************************************
  2426.   FUNCTION : delete_current_plane
  2427.  
  2428.   PURPOSE  : deletes Currenrt Plane out of the plane list.
  2429.  
  2430.   NOTES    : 
  2431.   RETURNS  :
  2432.  
  2433.   UPDATE   : 09.02.1993
  2434. ******************************************************************************/
  2435.  
  2436. static void delete_current_plane(void)
  2437.  
  2438. {
  2439.     TD_PLANE *TD_PLANE_element;
  2440.  
  2441.     TD_PLANE_element = TD_PLANE_current_element;
  2442.  
  2443.     /* Delete the element "TD_PLANE_element" out of the plane-list */
  2444.  
  2445.     if(TD_PLANE_length != 0) {
  2446.     if((*TD_PLANE_element).before != NULL) {
  2447.         (*(*TD_PLANE_element).before).next = (*TD_PLANE_element).next;
  2448.     }
  2449.     if((*TD_PLANE_element).next != NULL) {
  2450.         (*(*TD_PLANE_element).next).before = (*TD_PLANE_element).before;
  2451.     }
  2452.  
  2453.     /* Delete all the links which are connected with the deleted plane */
  2454.    
  2455.     get_links_and_delete_them(TD_PLANE_no);
  2456.  
  2457.     TD_LINK_current_element = TD_LINK_first_element;
  2458.  
  2459.     /* Decrement the number of the Planes */
  2460.  
  2461.     while(TD_LINK_current_element) {
  2462.         if((*TD_LINK_current_element).SOURCE.plane > TD_PLANE_no) {
  2463.         (*TD_LINK_current_element).SOURCE.plane--;
  2464.         }
  2465.         if((*TD_LINK_current_element).TARGET.plane > TD_PLANE_no) {
  2466.         (*TD_LINK_current_element).TARGET.plane--;
  2467.         }
  2468.         TD_LINK_current_element = (*TD_LINK_current_element).next;
  2469.     }
  2470.  
  2471.     TD_LINK_current_element = TD_LINK_last_element;
  2472.  
  2473.     TD_PLANE_length--;
  2474.  
  2475.     /* Update the three pointers "PLANE_current_element", 
  2476.        "PLANE_first_element" "PLANE_last_element."  */
  2477.  
  2478.     if(TD_PLANE_length == 0){
  2479.         TD_PLANE_current_element = NULL;
  2480.         TD_PLANE_first_element   = NULL;
  2481.         TD_PLANE_last_element    = NULL;
  2482.         TD_PLANE_no--;
  2483.     }else if((*TD_PLANE_element).next == NULL) {
  2484.         TD_PLANE_current_element = (*TD_PLANE_element).before;
  2485.         TD_PLANE_last_element    = TD_PLANE_current_element;
  2486.         TD_PLANE_no--;
  2487.     }else if((*TD_PLANE_element).before == NULL) {
  2488.         TD_PLANE_current_element = (*TD_PLANE_element).next;
  2489.         TD_PLANE_first_element   = TD_PLANE_current_element;
  2490.     }else{
  2491.         TD_PLANE_current_element = (*TD_PLANE_element).next;
  2492.     }
  2493.  
  2494.     free(TD_PLANE_element);
  2495.     }
  2496.  
  2497. }
  2498.  
  2499.  
  2500.  
  2501. /*****************************************************************************
  2502.   FUNCTION : forward_plane
  2503.  
  2504.   PURPOSE  : moves forward one list element in the plane list.
  2505.  
  2506.   NOTES    : 
  2507.   RETURNS  : Error = 0 ; Succes = 1
  2508.  
  2509.   UPDATE   : 09.02.1993
  2510. ******************************************************************************/
  2511.  
  2512. static int forward_plane(void)
  2513.  
  2514. {
  2515.     if(TD_PLANE_length != 0) {
  2516.     if((*TD_PLANE_current_element).next != NULL) {
  2517.         TD_PLANE_current_element = (*TD_PLANE_current_element).next;
  2518.         TD_PLANE_no++;
  2519.     }
  2520.     return 1;
  2521.     }else{
  2522.     return 0;
  2523.     }
  2524.  
  2525. }
  2526.  
  2527.  
  2528.  
  2529. /*****************************************************************************
  2530.   FUNCTION : backward_link
  2531.  
  2532.   PURPOSE  : moves backward one plane element in the link list.
  2533.  
  2534.   NOTES    : 
  2535.   RETURNS  : Error = 0 ; Succes = 1
  2536.  
  2537.   UPDATE   : 09.02.1993
  2538. ******************************************************************************/
  2539.  
  2540. static int backward_plane(void)
  2541.  
  2542. {
  2543.     if(TD_PLANE_length != 0) {
  2544.     if((*TD_PLANE_current_element).before != NULL) {
  2545.         TD_PLANE_current_element = (*TD_PLANE_current_element).before;
  2546.         TD_PLANE_no--;
  2547.     }
  2548.     return 1;
  2549.     }else{
  2550.     return 0;
  2551.     }
  2552. }
  2553.  
  2554.  
  2555.  
  2556. /*****************************************************************************
  2557.   FUNCTION : beginning_plane
  2558.  
  2559.   PURPOSE  : jumps to the beginning of the plane list.
  2560.  
  2561.   NOTES    : 
  2562.   RETURNS  : Error = 0 ; Succes = 1
  2563.  
  2564.   UPDATE   : 09.02.1993
  2565. ******************************************************************************/
  2566.  
  2567. static int beginning_plane(void)
  2568.  
  2569. {
  2570.     if(TD_PLANE_length != 0){
  2571.     TD_PLANE_current_element = TD_PLANE_first_element;
  2572.     TD_PLANE_no = 1;
  2573.     return 1;
  2574.     }else{
  2575.     return 0;
  2576.     }
  2577.  
  2578. }
  2579.  
  2580.  
  2581.  
  2582. /*****************************************************************************
  2583.   FUNCTION : end_plane
  2584.  
  2585.   PURPOSE  : jumps to the end of the plane list.
  2586.  
  2587.   NOTES    : 
  2588.   RETURNS  : Error = 0 ; Succes = 1
  2589.  
  2590.   UPDATE   : 09.02.1993
  2591. ******************************************************************************/
  2592.  
  2593. static int end_plane(void)
  2594.  
  2595. {
  2596.     if(TD_PLANE_length != 0) {
  2597.     TD_PLANE_current_element = TD_PLANE_last_element;
  2598.     TD_PLANE_no = TD_PLANE_length;
  2599.     return 1;
  2600.     }else{
  2601.     return 0;
  2602.     }
  2603.  
  2604. }
  2605.  
  2606.  
  2607.  
  2608. /*****************************************************************************
  2609.   FUNCTION : get_plane
  2610.  
  2611.   PURPOSE  : returns a pointer to the plane element "plane_no"
  2612.  
  2613.   NOTES    : 
  2614.   RETURNS  : returns a pointer to the plane element "plane_no" 
  2615.  
  2616.   UPDATE   : 09.02.1993
  2617. ******************************************************************************/
  2618.  
  2619. static TD_PLANE *get_plane(int plane_no)
  2620.  
  2621. {
  2622.     TD_PLANE *TD_PLANE_element = TD_PLANE_first_element;
  2623.     int counter = 1;
  2624.  
  2625.     while((TD_PLANE_element != NULL) && (counter != plane_no)) {
  2626.     counter++;
  2627.     TD_PLANE_element = (*TD_PLANE_element).next;
  2628.     }        
  2629.     return TD_PLANE_element;
  2630.  
  2631. }
  2632.  
  2633.  
  2634. /*****************************************************************************
  2635.  
  2636. ******************************************************************************/
  2637.  
  2638. /* end of file */
  2639. /* lines: 2644 */
  2640.  
  2641.  
  2642.  
  2643.